2012-06-19 Mark Holland <mark@mark-holland.me.uk>

* res/layout.main.xml: removed as no longer used
	 in pandroid 2.0

	* res/values/strings.xml: Added strings for simID,
	upTime, start, loading and agent stopped. Replicated
	in values-en and values-es
	
	* src/pandroid/agent/core.java: Added variables 
	for simID and upTime
 	
	* src/pandroid/agent/PandroidAgent.java: commented
	out unnecessary code from version 1.0. Removed
	absolute tab height as it interferes with high
	density screens.

	* src/pandroid/agent/PandroidAgentListener.java: 
	Android version is now set as per device rather 
	than a fixed string. simID, upTime and networkOperator 	methods
	and then added to XML

	* src/pandroid/agent/setup.java: commented
	out unnecessary code from version 1.0

	* src/pandroid/agent/SMSActivity.java: Started work

	* src/pandroid/agent/SMSBroadcastReceiver.java: 
	Started work

	* src/pandroid/agent/status.java: Created onStart
	method to better follow android standard. run()
	is executed here. Fixed way toasts for connection 
	messages are handled. Added textviews for simID 
	and upTime values. added start/stop, show and hide 
	XML buttons for debugging purposes.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6601 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
markholland 2012-06-19 22:37:03 +00:00
parent fde60847ac
commit 240209747b
16 changed files with 542 additions and 277 deletions

View File

@ -30,6 +30,17 @@
android:name=".Help"
android:label="@string/help_str"
android:theme="@android:style/Theme.Dialog"
/>
<receiver android:name=".SMSBroadcastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
<service
android:name=".SMSActivity"
android:label="@string/sms_activity_str"
android:theme="@android:style/Theme.Dialog"
/>
</application>
@ -40,6 +51,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.BATTERY_STATS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-feature android:name="android.hardware.sensor.light" />
<uses-feature android:name="android.hardware.location" />

View File

@ -1,6 +1,43 @@
2012-06-08 Sergio Martin <sergio.martin@artica.es>
* ChangeLog: Create the android agent change
log file
2012-06-19 Mark Holland <mark@mark-holland.me.uk>
* res/layout.main.xml: removed as no longer used
in pandroid 2.0
* res/values/strings.xml: Added strings for simID,
upTime, start, loading and agent stopped. Replicated
in values-en and values-es
* src/pandroid/agent/core.java: Added variables
for simID and upTime
* src/pandroid/agent/PandroidAgent.java: commented
out unnecessary code from version 1.0. Removed
absolute tab height as it interferes with high
density screens.
* src/pandroid/agent/PandroidAgentListener.java:
Android version is now set as per device rather
than a fixed string. simID, upTime and networkOperator methods
and then added to XML
* src/pandroid/agent/setup.java: commented
out unnecessary code from version 1.0
* src/pandroid/agent/SMSActivity.java: Started work
* src/pandroid/agent/SMSBroadcastReceiver.java:
Started work
* src/pandroid/agent/status.java: Created onStart
method to better follow android standard. run()
is executed here. Fixed way toasts for connection
messages are handled. Added textviews for simID
and upTime values. added start/stop, show and hide
XML buttons for debugging purposes.
2012-06-08 Sergio Martin <sergio.martin@artica.es>
* ChangeLog: Create the android agent change
log file

View File

@ -1,154 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:padding="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/confTitle"
android:gravity="center_horizontal"
android:textSize="20dip"
android:paddingBottom="5dp"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/header"
android:layout_below="@id/title"
android:paddingTop="4dp"
>
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="@drawable/logo"
android:background="@android:color/white"
/>
<TextView
android:id="@+id/fieldSummary"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/summary"
android:layout_below="@id/logo"
android:layout_toRightOf="@id/logo"
android:layout_alignTop="@id/logo"
android:paddingLeft="5dp"
android:textSize="13dip"
/>
</LinearLayout>
<TextView
android:id="@+id/lastContactInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/loading"
android:gravity="right"
android:layout_below="@id/header"
/>
<TextView
android:id="@+id/field1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/serverAddr"
android:layout_below="@id/lastContactInfo"
android:paddingTop="5dp"
/>
<EditText android:id="@+id/serverAddrInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/field1"
/>
<TextView
android:id="@+id/field2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/serverPort"
android:layout_below="@id/serverAddrInput"
/>
<EditText android:id="@+id/serverPortInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/field2"
/>
<TextView
android:id="@+id/field3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/interval"
android:layout_below="@id/serverPortInput"
/>
<EditText android:id="@+id/intervalInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/field3"
android:maxLines="1"
/>
<TextView
android:id="@+id/field4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/agent"
android:layout_below="@id/intervalInput"
/>
<EditText android:id="@+id/agentNameInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/field4"
/>
<CheckBox android:id="@+id/checkGpsReport"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/gpsReport"
android:layout_below="@id/agentNameInput"
android:textSize="14dip"
android:textColor="#bbbbbb"
>
</CheckBox>
<Button android:id="@+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/checkGpsReport"
android:layout_alignParentRight="true"
android:gravity="right"
android:text="@string/update"
/>
<Button android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/update"
android:text="@string/reset"
android:layout_below="@id/update"
android:gravity="left"
/>
<!--<Button android:id="@+id/starStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/reset"
android:layout_alignTop="@id/reset"
android:text="@string/starStop"
android:layout_below="@id/reset"
/>-->
<TextView
android:id="@+id/xml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="left"
android:layout_below="@id/reset"
/>
</RelativeLayout>
</ScrollView>
</LinearLayout>

View File

@ -159,7 +159,72 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!--
<TextView
android:id="@+id/sim_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sim_id"
android:textSize="14dip"
android:textStyle="bold"
/>
<TextView
android:id="@+id/sim_id_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/uptime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/uptime"
android:textSize="14dip"
android:textStyle="bold"
/>
<TextView
android:id="@+id/uptime_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/networkoperator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/networkoperator"
android:textSize="14dip"
android:textStyle="bold"
/>
<TextView
android:id="@+id/networkoperator_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!-- <TextView
android:id="@+id/sms_received"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sms_received"
android:textSize="14dip"
android:textStyle="bold"
/>
<TextView
android:id="@+id/sms_received_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
-->
<Button
android:id="@+id/start"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/start"
/>
<Button
android:id="@+id/stop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Stop"
/>
<Button
android:id="@+id/get_xml"
android:layout_width="fill_parent"
@ -173,7 +238,14 @@
android:text="..."
android:gravity="left"
/>
-->
<Button
android:id="@+id/hide_xml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hide xml"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -6,14 +6,14 @@
<string name="setup_str">Setup</string>
<string name="app_name">Pandroid Agent</string>
<string name="interval">Interval:</string>
<string name="update">Update conf.</string>
<string name="update">Update configuration.</string>
<string name="reset">Set default</string>
<string name="serverAddr">Server Address:</string>
<string name="serverPort">Server Port:</string>
<string name="confTitle">Pandroid Agent Configuration</string>
<string name="agent">Agent name:</string>
<string name="gpsReport">Report GPS data</string>
<string name="memoryReport">Report memory system</string>
<string name="memoryReport">Report available memory</string>
<string name="taskReport">Report task</string>
<string name="gpsMode">GPS Mode</string>
<string name="gpsCurrent">Current position (high battery cost)</string>
@ -29,7 +29,7 @@
<string name="orientation">Orientation</string>
<string name="proximity">Proximity</string>
<string name="incorrect_update">Unsucessful update options.</string>
<string name="correct_update">sucessful update options.</string>
<string name="correct_update">sucessfully updated configuration.</string>
<string name="task">Task</string>
<string name="memory">Memory</string>
<string name="help_label_str">Help</string>
@ -48,4 +48,17 @@
Pandroid Agent is an Android Pandora FMS agent for Pandora FMS. &lt;p&gt;
Pandora FMS is a general purpose monitoring system. With android agent you can get GPS information of your device, know how much battery left, memory on device. This could be expanded in the future to report if a given process is running, very useful to use the agent on embedded devices on tablets to report to a central server. Also can be expanded to get information given by the user for other app and stored in the device or doing a lot of things more. Complete source code is provided.&lt;p&gt;See more about Pandora FMS at &lt;a href=&quot;http://pandorafms.org&quot;&gt;http://pandorafms.org&lt;/a&gt;&lt;/p&gt;
</string>
<string name="start">Start</string>
<string name="correct_start">Connection successful</string>
<string name="contact_stopped_str">Agent Stopped</string>
<string name="sim_id">Sim ID:</string>
<string name="sim_id_value"/>
<string name="loading_str">Loading...</string>
<string name="uptime">Device up time:</string>
<string name="uptime_value"/>
<string name="sms_received">Received SMS: </string>
<string name="sms_received_value"/>
<string name="sms_activity_str">SMS</string>
<string name="networkoperator">Network operator:</string>
<string name="networkoperator_value"/>
</resources>

View File

@ -48,4 +48,15 @@
Pandroid Agent es un agente en Android para Pandora FMS. &lt;p&gt;
Pandora FMS es un sistema de monitorizaci&#243;n de prop&#243;sito general. Con el agente en Android puedes monitorizar GPS, cuanta batería le queda al dispositivo, memoria disponible. Este podrá expandirse en el futuro para reportar si un proceso esta en ejecución, siendo muy útil para sistemas embebidos en servidores centrales. Tambien se puede expandir para obtener información de otras aplicaciones en el dispositivo o hacer otras cosas mas. El código fuente esta disponible.&lt;p&gt;Puedes informarte de esto y mas en Pandora FMS en &lt;a href=&quot;http://pandorafms.org&quot;&gt;http://pandorafms.org&lt;/a&gt;&lt;/p&gt;
</string>
<string name="start">Iniciar</string>
<string name="correct_start">Conexion con exito</string>
<string name="contact_stopped_str">Agente parado</string>
<string name="sim_id">Sim ID:</string>
<string name="sim_id_value"/>
<string name="loading_str">Cargando...</string>
<string name="uptime">Tiempo encendido:</string>
<string name="uptime_value"/>
<string name="sms_received">SMS recibido: </string>
<string name="sms_received_value"/>
<string name="sms_activity_str">SMS</string>
</resources>

View File

@ -6,14 +6,14 @@
<string name="setup_str">Setup</string>
<string name="app_name">Pandroid Agent</string>
<string name="interval">Interval:</string>
<string name="update">Update conf.</string>
<string name="update">Update configuration.</string>
<string name="reset">Set default</string>
<string name="serverAddr">Server Address:</string>
<string name="serverPort">Server Port:</string>
<string name="confTitle">Pandroid Agent Configuration</string>
<string name="agent">Agent name:</string>
<string name="gpsReport">Report GPS data</string>
<string name="memoryReport">Report memory system</string>
<string name="memoryReport">Report available memory</string>
<string name="taskReport">Report task</string>
<string name="gpsMode">GPS Mode</string>
<string name="gpsCurrent">Current position (high battery cost)</string>
@ -29,7 +29,7 @@
<string name="orientation">Orientation</string>
<string name="proximity">Proximity</string>
<string name="incorrect_update">Unsucessful update options.</string>
<string name="correct_update">sucessful update options.</string>
<string name="correct_update">sucessfully updated configuration.</string>
<string name="task">Task</string>
<string name="memory">Memory</string>
<string name="help_label_str">Help</string>
@ -48,4 +48,17 @@
Pandroid Agent is an Android Pandora FMS agent for Pandora FMS. &lt;p&gt;
Pandora FMS is a general purpose monitoring system. With android agent you can get GPS information of your device, know how much battery left, memory on device. This could be expanded in the future to report if a given process is running, very useful to use the agent on embedded devices on tablets to report to a central server. Also can be expanded to get information given by the user for other app and stored in the device or doing a lot of things more. Complete source code is provided.&lt;p&gt;See more about Pandora FMS at &lt;a href=&quot;http://pandorafms.org&quot;&gt;http://pandorafms.org&lt;/a&gt;&lt;/p&gt;
</string>
<string name="start">Start</string>
<string name="correct_start">Connection successful</string>
<string name="contact_stopped_str">Agent Stopped</string>
<string name="sim_id">Sim ID:</string>
<string name="sim_id_value"/>
<string name="loading_str">Loading...</string>
<string name="uptime">Device up time:</string>
<string name="uptime_value"/>
<string name="sms_received">Received SMS: </string>
<string name="sms_received_value"/>
<string name="sms_activity_str">SMS</string>
<string name="networkoperator">Network operator:</string>
<string name="networkoperator_value"/>
</resources>

View File

@ -6,8 +6,9 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.util.Log;
//import android.util.Log;
public class Core {
//The 181 is the first invalid value between 180 and -180 values.
@ -19,12 +20,12 @@ public class Core {
static final long CONST_INVALID_CONTACT = -1;
static final int CONST_CONTACT_ERROR = 0;
static volatile public String defaultServerAddr = "farscape.artica.es";
static volatile public String defaultServerAddr = "farscape.artica.es"; //master address
static volatile public String defaultServerPort = "41121";
static volatile public int defaultInterval = 300;
static volatile public String defaultAgentName = "pandroid";
static volatile public String defaultGpsStatus = "disabled"; // "disabled" or "enabled"
static volatile public String defaultMemoryStatus = "disabled"; // "disabled" or "enabled"
static volatile public String defaultGpsStatus = "enabled"; // "disabled" or "enabled"
static volatile public String defaultMemoryStatus = "enabled"; // "disabled" or "enabled"
static volatile public String defaultTaskStatus = "disabled"; // "disabled" or "enabled"
static volatile public String defaultTask = "";
static volatile public String defaultTaskHumanName = "";
@ -32,6 +33,11 @@ public class Core {
static volatile public long defaultRam = 0;
static volatile public long defaultContact = 0;
static volatile public int defaultContactError = 0;
static volatile public String defaultSimID = "";
static volatile public long defaultUpTime = 0;
static volatile public int defaultSMSReceived = 0;
static volatile public String defaultMobileOperator = "";
static volatile public Context con = null;
static volatile public AlarmManager am = null;
@ -47,6 +53,10 @@ public class Core {
static volatile public String taskStatus = defaultTaskStatus;
static volatile public String task = defaultTask;
static volatile public String taskHumanName = defaultTaskHumanName;
static volatile public String simID = ""; //fix
static volatile public long upTime = defaultUpTime; //mark device uptime including deep sleep
static volatile public int SMSReceived = defaultSMSReceived;
static volatile public String networkOperator = defaultMobileOperator;
static volatile public float latitude = CONST_INVALID_COORDS;
static volatile public float longitude = CONST_INVALID_COORDS;
@ -91,19 +101,6 @@ public class Core {
startAgentListener(context);
}
static public String getSimID(Context context) {
if (con == null) {
con = context;
}
String simID = null;
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager m_telephonyManager = (TelephonyManager) con.getSystemService(serviceName);
simID = m_telephonyManager.getSimSerialNumber();
return simID;
}
static public void loadLastValues(Context context) {
if (con == null) {
con = context;
@ -127,6 +124,9 @@ public class Core {
totalRamKb = agentPreferences.getLong("totalRamKb", Core.defaultRam);
lastContact = agentPreferences.getLong("lastContact", Core.defaultContact);
contactError = agentPreferences.getInt("contactError", Core.defaultContactError);
simID = agentPreferences.getString("simID", Core.defaultSimID);
upTime = agentPreferences.getLong("upTime", Core.defaultUpTime);
networkOperator = agentPreferences.getString("networkOperator", Core.defaultMobileOperator);
}
static public void loadConf(Context context) {
@ -141,7 +141,8 @@ public class Core {
serverAddr = agentPreferences.getString("serverAddr", Core.defaultServerAddr);
serverPort = agentPreferences.getString("serverPort", Core.defaultServerPort);
interval = agentPreferences.getInt("interval", Core.defaultInterval);
agentName = agentPreferences.getString("agentName", Core.defaultAgentName + getSimID(con));
//fix agent name to mark
agentName = agentPreferences.getString("agentName", Core.defaultAgentName + "_mark_v");
gpsStatus = agentPreferences.getString("gpsStatus", Core.defaultGpsStatus);
memoryStatus = agentPreferences.getString("memoryStatus", Core.defaultMemoryStatus);
taskStatus = agentPreferences.getString("taskStatus", Core.defaultTaskStatus);
@ -152,13 +153,13 @@ public class Core {
static public boolean updateConf(Context context) {
return updateConf(context, serverAddr, serverPort, interval, agentName,
gpsStatus, memoryStatus, taskStatus, task, taskHumanName);
gpsStatus, memoryStatus, taskStatus, task, taskHumanName, simID, upTime, networkOperator);
}
static public boolean updateConf(Context context, String _serverAddr,
String _serverPort, int _interval, String _agentName, String _gpsStatus,
String _memoryStatus, String _taskStatus, String _task,
String _taskHumanName) {
String _taskHumanName, String _simID, long _upTime, String _networkOperator) {
if (con == null) {
con = context;
}
@ -177,6 +178,9 @@ public class Core {
editor.putString("taskStatus", _taskStatus);
editor.putString("task", _task);
editor.putString("taskHumanName", _taskHumanName);
editor.putString("SimID", _simID);
editor.putLong("UpTime", _upTime);
editor.putString("networkOperator", _networkOperator);
if (editor.commit()) {
return true;

View File

@ -17,7 +17,7 @@ package pandroid.agent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
//import android.util.Log;
public class EventReceiver extends BroadcastReceiver {

View File

@ -14,58 +14,61 @@
package pandroid.agent;
import java.util.Date;
//import java.util.Date;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
//import android.app.Activity;
//import android.app.AlarmManager;
//import android.app.PendingIntent;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
//import android.content.ComponentName;
//import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
//import android.content.SharedPreferences;
//import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
//import android.telephony.TelephonyManager;
//import android.view.KeyEvent;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.View.OnKeyListener;
//import android.view.inputmethod.InputMethodManager;
//import android.widget.Button;
//import android.widget.CheckBox;
//import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TextView;
//import android.widget.TextView;
public class PandroidAgent extends TabActivity {
//public class PandroidAgent extends Activity {
Handler h = new Handler();
int defaultInterval = 300;
int defaultInterval = 300; //important
/*
String defaultServerPort = "41121";
String defaultServerAddr = "farscape.artica.es";
String defaultAgentName = "pandroid";
String defaultGpsStatus = "disabled"; // "disabled" or "enabled"
*/
//boolean alarmEnabled;
boolean alarmEnabled;
//boolean showLastXML = true;
boolean showLastXML = true;
String lastGpsContactDateTime = "";
//String lastGpsContactDateTime = "";
/*
Thread thread = new Thread();
ComponentName service = null;
PendingIntent sender = null;
AlarmManager am = null;
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//if removed, battery -1 and agent reverts to defaults in core
Core.restartAgentListener(getApplicationContext());
final TabHost tabHost = getTabHost();
tabHost.addTab
@ -82,8 +85,8 @@ public class PandroidAgent extends TabActivity {
.setContent(new Intent(this, Setup.class))
);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height=45;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height=45;
//tabHost.getTabWidget().getChildAt(0).getLayoutParams();
//tabHost.getTabWidget().getChildAt(1).getLayoutParams();
}
}

View File

@ -29,30 +29,36 @@ import org.apache.commons.lang3.StringEscapeUtils;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.app.ActivityManager.RunningAppProcessInfo;
//import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
//import android.content.pm.PackageManager;
//import android.hardware.Sensor;
//import android.hardware.SensorEvent;
//import android.hardware.SensorEventListener;
//import android.hardware.SensorManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.Log;
public class PandroidAgentListener extends Service {
public static final String LOG_TAG = "mark";
Handler h = new Handler();
int defaultInterval = 300;
@ -65,6 +71,12 @@ public class PandroidAgentListener extends Service {
String defaultTask = "";
String defaultTaskHumanName = "";
String lastGpsContactDateTime = "";
String osversion = "";
String defaultSimID = "";
String defaultUpTime = "0";
String defaultNetworkOperator = "";
String defaultSMSReceived = "5";
boolean showLastXML = true;
@ -145,10 +157,11 @@ public class PandroidAgentListener extends Service {
String agentName = getSharedData("PANDROID_DATA", "agentName", defaultAgentName, "string");
String interval = getSharedData("PANDROID_DATA", "interval", Integer.toString(defaultInterval), "integer");
buffer += "<agent_data " +
"description='' group='' os_name='android' os_version='2.1' " +
"description='' group='' os_name='android' os_version='"+Build.VERSION.RELEASE+"' " + //change to read real version of os
"interval='"+ interval +"' version='4.0(Build 111012)' " +
"timestamp='" + getHumanDateTime(-1) + "' agent_name='" + agentName + "' " +
"timezone_offset='0'" + gpsData +">\n";
@ -159,17 +172,21 @@ public class PandroidAgentListener extends Service {
String orientation = getSharedData("PANDROID_DATA", "orientation", "361", "float");
String proximity = getSharedData("PANDROID_DATA", "proximity", "-1.0", "float");
String batteryLevel = getSharedData("PANDROID_DATA", "batteryLevel", "-1", "integer");
String taskStatus = getSharedData("PANDROID_DATA", "taskStatus", "disabled", "string");
String taskRun = getSharedData("PANDROID_DATA", "taskRun", "false", "string");
//String taskStatus = getSharedData("PANDROID_DATA", "taskStatus", "disabled", "string");
//String taskRun = getSharedData("PANDROID_DATA", "taskRun", "false", "string");
String taskHumanName = getSharedData("PANDROID_DATA", "taskHumanName", "", "string");
taskHumanName = StringEscapeUtils.escapeHtml4(taskHumanName);
String task = getSharedData("PANDROID_DATA", "task", "", "string");
//String task = getSharedData("PANDROID_DATA", "task", "", "string");
String memoryStatus = getSharedData("PANDROID_DATA", "memoryStatus", defaultMemoryStatus, "string");
String availableRamKb = getSharedData("PANDROID_DATA", "availableRamKb", "0" , "long");
String totalRamKb = getSharedData("PANDROID_DATA", "totalRamKb", "0", "long");
String sim_ID = getSharedData("PANDROID_DATA", "simID", defaultSimID, "string");
String upTime = getSharedData("PANDROID_DATA", "upTime", defaultUpTime, "long");
String networkOperator = getSharedData("PANDROID_DATA", "networkOperator", defaultNetworkOperator, "string");
//String SMSReceived = getSharedData("PANDROID_DATA", "SMSReceived", defaultSMSReceived, "integer");
buffer += buildmoduleXML("battery_level", "The actually device battery level", "generic_data", batteryLevel);
buffer += buildmoduleXML("battery_level", "The current Battery level", "generic_data", batteryLevel);
if(!orientation.equals("361.0")) {
buffer += buildmoduleXML("orientation", "The actually device orientation (in degrees)", "generic_data", orientation);
@ -197,15 +214,19 @@ public class PandroidAgentListener extends Service {
Float freeMemory = new Float((Float.valueOf(availableRamKb) / Float.valueOf(totalRamKb)) * 100.0);
DecimalFormat formatPercent = new DecimalFormat("#.##");
buffer += buildmoduleXML("freeRamMemory", "The available ram in percent value.", "generic_data",
buffer += buildmoduleXML("freeRamMemory", "The percentage of available ram.", "generic_data",
formatPercent.format(freeMemory.doubleValue()));
}
//buffer += buildmoduleXML("last_gps_contact", "Datetime of the last geo-location contact", "generic_data", lastGpsContactDateTime);
buffer += buildmoduleXML("simID", "The Sim ID.", "generic_data_string", sim_ID);
buffer += buildmoduleXML("upTime","Total device uptime in seconds.", "generic_data", upTime);
buffer += buildmoduleXML("networkOperator","Currently registered network operator", "generic_data_string", networkOperator);
//buffer += buildmoduleXML("SMSRecieved","Number of SMS recieved", "generic_data", SMSReceived);
// End_Modules
buffer += "</agent_data>";
//Log.v("mark",buffer);
return buffer;
}
@ -314,7 +335,7 @@ public class PandroidAgentListener extends Service {
registerReceiver(batteryLevelReceiver, batteryLevelFilter);
}
private void sensors() {
/*private void sensors() {
// Sensor listeners
SensorEventListener orientationLevelReceiver = new SensorEventListener() {
@ -370,8 +391,8 @@ public class PandroidAgentListener extends Service {
(20));
//SensorManager.SENSOR_DELAY_UI );
}
}
}//end sensors
*/
private void updateValues() {
batteryLevel();
String gpsStatus = getSharedData("PANDROID_DATA", "gpsStatus", defaultGpsStatus, "string");
@ -389,6 +410,10 @@ public class PandroidAgentListener extends Service {
//sensors();
//getTaskStatus();
getMemoryStatus();
getSimID();
getUpTime();
getNetworkOperator();
//getSMSReceived();
}
private void getMemoryStatus() {
@ -421,7 +446,7 @@ public class PandroidAgentListener extends Service {
putSharedData("PANDROID_DATA", "totalRamKb", "" + totalRamKb, "long");
}
private void getTaskStatus() {
/*private void getTaskStatus() {
String taskStatus = getSharedData("PANDROID_DATA", "taskStatus", defaultTaskStatus, "string");
String task = getSharedData("PANDROID_DATA", "task", defaultTask, "string");
String taskHumanName = getSharedData("PANDROID_DATA", "taskHumanName", defaultTaskHumanName, "string");
@ -445,8 +470,54 @@ public class PandroidAgentListener extends Service {
}
}
putSharedData("PANDROID_DATA", "taskRun", run, "string");
}//end gettaskstatus
*/
/**
* Retrieves the simID of the device if available
*/
public void getSimID(){
String simID = getSharedData("PANDROID_DATA", "simID", defaultSimID, "string");
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(serviceName);
simID = telephonyManager.getSimSerialNumber();
putSharedData("PANDROID_DATA", "simID", simID, "string");
}
/**
* Retrieves the time in seconds since the device was switched on
*/
public void getUpTime(){
String upTime = defaultUpTime;
upTime = ""+SystemClock.elapsedRealtime()/1000;
//Log.v(LOG_TAG, upTime);
putSharedData("PANDROID_DATA", "upTime", upTime, "long");
}
public void getNetworkOperator(){
String networkOperator = defaultNetworkOperator;
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(serviceName);
networkOperator = telephonyManager.getNetworkOperatorName();
if(networkOperator != null)
Log.v(LOG_TAG, networkOperator);
putSharedData("PANDROID_DATA", "networkOperator", networkOperator, "string");
}
/*
public void getSMSReceived(){
String SMSReceived = defaultSMSReceived;
SMSReceived = getSharedData("SMS_DATA", "SMSReceived", defaultSMSReceived, "integer");
Log.v(LOG_TAG, "SMSReceived:"+SMSReceived);
//putSharedData("PANDROID_DATA", "upTime", upTime, "long");
}
*/
private void putSharedData(String preferenceName, String tokenName, String data, String type) {
int mode = Activity.MODE_PRIVATE;
SharedPreferences agentPreferences = getSharedPreferences(preferenceName, mode);
@ -539,6 +610,8 @@ public class PandroidAgentListener extends Service {
return humanDateTime;
}
///////////////////////////////////////////
// Getting values from device functions
@ -546,21 +619,20 @@ public class PandroidAgentListener extends Service {
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
putSharedData("PANDROID_DATA", "latitude", new Double(loc.getLatitude()).toString(), "float");
putSharedData("PANDROID_DATA", "longitude", new Double(loc.getLongitude()).toString(), "float");
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

View File

@ -27,7 +27,7 @@ import java.net.UnknownHostException;
class tentacle_client {
// Return 0 when success, -1 when error
public int tentacle_client(String args[]) {
public int tentacle_client(String args[]) {
int port = 41121;
String send = null;

View File

@ -0,0 +1,31 @@
package pandroid.agent;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
public class SMSActivity {
private static final String TAG = "SMSActivity";
static public void SMSReceived(Context context){
int defaultSMSReceived = 0;
int mode = Activity.MODE_PRIVATE;
SharedPreferences pref = context.getSharedPreferences("SMS_DATA", mode);
int a = pref.getInt("SMSReceived", defaultSMSReceived);
Log.i(TAG, "sms received: " + a);
a++;
Log.i(TAG, "sms received: " + a);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("SMSReceived", a);
}
}

View File

@ -0,0 +1,29 @@
package pandroid.agent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class SMSBroadcastReceiver extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private static final String TAG = "SMSBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Intent recieved: " + intent.getAction());
//if (intent.getAction() == "android.provider.Telephony.SMS_RECEIVED") {
//sms recieved
//Intent i = new Intent(context, SMSActivity.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(i);
// SMSActivity.SMSReceived(this);
// }//end if
}//end onRecieve
}//end class

View File

@ -1,33 +1,33 @@
package pandroid.agent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
//import android.app.ActivityManager;
//import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
//import android.content.pm.PackageManager;
//import android.content.pm.PackageManager.NameNotFoundException;
//import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
//import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Spinner;
//import android.widget.ProgressBar;
//import android.widget.Spinner;
import android.widget.Toast;
public class Setup extends Activity {
private HashMap<String, String> listProcesses;
//private HashMap<String, String> listProcesses;
/** Called when the activity is first created. */
@ -35,7 +35,7 @@ public class Setup extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listProcesses = new HashMap<String, String>();
// listProcesses = new HashMap<String, String>();
setContentView(R.layout.setup);
@ -96,6 +96,8 @@ public class Setup extends Activity {
});
}
/*
private void loadInBackgroundProcessInExecution() {
new GetProcessInExecutionAsyncTask().execute();
}
@ -132,10 +134,11 @@ public class Setup extends Activity {
}
}
@Override
protected void onPostExecute(Void unused)
{
/*
Spinner combo = (Spinner)findViewById(R.id.processes_combo);
ArrayList<String> listProcess = new ArrayList<String>(listProcesses.keySet());
ArrayList<String> listProcessHuman = new ArrayList<String>(listProcesses.values());
@ -160,6 +163,7 @@ public class Setup extends Activity {
position = listProcess.indexOf(Core.task);
}
}
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_spinner_item, listProcessHuman);
@ -177,16 +181,20 @@ public class Setup extends Activity {
Button button = (Button)findViewById(R.id.update);
button.setEnabled(true);
*/
}
}
}*/
private void getDataFromView() {
// Init form values
EditText editText;
CheckBox checkBox;
Spinner combo;
//Spinner combo;
editText = (EditText) findViewById(R.id.serverAddrInput);
Core.serverAddr = editText.getText().toString();

View File

@ -3,14 +3,18 @@ package pandroid.agent;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.content.*;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Status extends Activity {
Handler h = new Handler();
@ -25,9 +29,19 @@ public class Status extends Activity {
showLastValues();
updateLastContactInfo();
//connect automatically
//Core.restartAgentListener(getApplicationContext());
setButtonEvents();
// Update the UI each second
h.post(new Runnable() {
@Override
}
public void onStart(){
super.onStart();
h.post(new Runnable() {
public void run() {
Core.loadLastValues(getApplicationContext());
showLastValues();
@ -63,10 +77,10 @@ public class Status extends Activity {
}
private void updateLastXML() {
/*
TextView xml = (TextView) this.findViewById(R.id.xml);
Core.restartAgentListener(getApplicationContext());
//Core.restartAgentListener(getApplicationContext());
SharedPreferences agentPreferences = getSharedPreferences(
getString(R.string.const_string_preferences),
@ -75,16 +89,29 @@ public class Status extends Activity {
String lastXML = agentPreferences.getString("lastXML", "[no data]");
xml.setText("Last XML builded: \n\n" + lastXML);
*/
}
private void hideLastXML(){
TextView xml = (TextView) this.findViewById(R.id.xml);
xml.setText("");
}
private void updateLastContactInfo() {
long lastContact = Core.lastContact;
int contactError = Core.contactError;
boolean alarmEnabled = Core.alarmEnabled;
Date date = new Date();
long timestamp = date.getTime() / 1000;
long timeAgo = -1;
//loading until error or connects
TextView lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo_label_str);
lastContactInfo.setTextColor(Color.parseColor("#FF0000"));
lastContactInfo.setText(getString(R.string.loading));
if(lastContact != -1){
timeAgo = timestamp - lastContact;
}
@ -97,7 +124,21 @@ public class Status extends Activity {
String stringAgo = "";
if(lastContact == -1) {
//Check connection first
if(!alarmEnabled){
lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo_label_str);
lastContactInfo.setTextColor(Color.parseColor("#FF0000"));
lastContactInfo.setText(getString(R.string.contact_stopped_str));
}
else if(contactError == 1) {
lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo_label_str);
lastContactInfo.setTextColor(Color.parseColor("#FF0000"));
lastContactInfo.setText(getString(R.string.conctact_error_str));
//stopAgentListener();
}
else if(lastContact == -1) {
stringAgo = getString(R.string.never_str);
}
else if(timeAgo == 0) {
@ -105,39 +146,88 @@ public class Status extends Activity {
}
else {
stringAgo = timeAgo + " " + getString(R.string.seconds_str);
}
if(contactError == 1) {
TextView lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo_label_str);
lastContactInfo.setTextColor(Color.parseColor("#FF0000"));
lastContactInfo.setText(getString(R.string.conctact_error_str));
//stopAgentListener();
}
else {
TextView lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo_label_str);
lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo_label_str);
lastContactInfo.setTextColor(Color.parseColor("#00FF00"));
lastContactInfo.setText(getString(R.string.last_contact_str) + stringAgo);
}
}
private void setButtonEvents() {
// Set update button events
Button updateButton = (Button) findViewById(R.id.start);
Button xml = (Button) findViewById(R.id.get_xml);
Button hidexml = (Button) findViewById(R.id.hide_xml);
Button stop = (Button) findViewById(R.id.stop);
xml.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
updateLastXML();
}
});
hidexml.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideLastXML();
}
});
stop.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Core.stopAgentListener();
}
});
updateButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
boolean result = Core.updateConf(getApplicationContext());
if (result) {
Toast toast = Toast.makeText(getApplicationContext(),
getString(R.string.correct_start),
Toast.LENGTH_SHORT);
toast.show();
}
else {
Toast toast = Toast.makeText(getApplicationContext(),
getString(R.string.incorrect_update),
Toast.LENGTH_SHORT);
toast.show();
}
Core.restartAgentListener(getApplicationContext());
}
});
}
private void showLastValues() {
// latitude
TextView textView = (TextView)findViewById(R.id.latitude_value_str);
textView.setText("");
if (Core.latitude != Core.CONST_INVALID_COORDS) {
textView.setText("" + Core.latitude);
}
// longitude
textView = (TextView)findViewById(R.id.longitude_value_str);
textView.setText("");
if (Core.longitude != Core.CONST_INVALID_COORDS) {
textView.setText("" + Core.longitude);
}
//Battery level
textView = (TextView)findViewById(R.id.battery_value_str);
textView.setText("");
if (Core.batteryLevel != Core.CONST_INVALID_BATTERY_LEVEL) {
textView.setText("" + Core.batteryLevel);
}
/*
textView = (TextView)findViewById(R.id.orientation_value_str);
textView.setText("");
@ -167,7 +257,7 @@ public class Status extends Activity {
textView.setText(text);
}
*/
// freeMemory
textView = (TextView)findViewById(R.id.memory_value_str);
textView.setText("");
if (Core.memoryStatus.equals("enabled")) {
@ -176,5 +266,29 @@ public class Status extends Activity {
textMemory = textMemory.replaceFirst("%i", "" + Core.totalRamKb);
textView.setText(textMemory);
}
// simID
textView = (TextView)findViewById(R.id.sim_id_value);
textView.setText("");
if (Core.simID != null) {
textView.setText("" + Core.simID);
}
// upTime
textView = (TextView)findViewById(R.id.uptime_value);
textView.setText("");
if (Core.upTime != 0) {
textView.setText("" + Core.upTime+" Seconds");
}
// mobile operator
textView = (TextView)findViewById(R.id.networkoperator_value);
textView.setText("");
if (Core.networkOperator != null) {
textView.setText("" + Core.networkOperator);
}
// SMSReceived
/*
textView = (TextView)findViewById(R.id.sms_received_value);
textView.setText("");
textView.setText("" + Core.getSMSReceived(getApplicationContext()));
*/
}
}