2011-01-26 Sergio Martin <sergio.martin@artica.es>
* android android/default.properties android/.classpath android/proguard.cfg android/assets android/.project android/AndroidManifest.xml android/src android/src/pandroid android/src/pandroid/agent android/src/pandroid/agent/PandroidAgentTentacle.java android/src/pandroid/agent/PandroidAgent.java android/bin android/bin/pandroid android/bin/pandroid/agent android/bin/pandroid/agent/PandroidAgent$8.class android/bin/pandroid/agent/PandroidAgent$9.class android/bin/pandroid/agent/PandroidAgent.class android/bin/pandroid/agent/R$id.class android/bin/pandroid/agent/PandroidAgent$MyLocationListener.class android/bin/pandroid/agent/R$string.class android/bin/pandroid/agent/tentacle_client.class android/bin/pandroid/agent/R$attr.class android/bin/pandroid/agent/R.class android/bin/pandroid/agent/R$layout.class android/bin/pandroid/agent/PandroidAgent$1.class android/bin/pandroid/agent/PandroidAgent$2.class android/bin/pandroid/agent/PandroidAgent$3.class android/bin/pandroid/agent/PandroidAgent$4.class android/bin/pandroid/agent/R$drawable.class android/bin/pandroid/agent/PandroidAgent$5.class android/bin/pandroid/agent/PandroidAgent$6.class android/bin/pandroid/agent/PandroidAgent$7.class android/bin/resources.ap_ android/bin/Copy of Copy of Pandroid Agent.apk android/bin/classes.dex android/res android/res/values android/res/values/strings.xml android/res/drawable-hdpi android/res/drawable-hdpi/logo.png android/res/drawable-hdpi/icon.png android/res/drawable-ldpi android/res/drawable-ldpi/icon.png android/res/drawable-mdpi android/res/drawable-mdpi/icon.png android/res/layout android/res/layout/main.xml android/gen android/gen/pandroid android/gen/pandroid/agent android/gen/pandroid/agent/R.java: Created the first android agent with report of battery level and basic GPS location coordinates report git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3779 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
cb50725bae
commit
412b9a7a63
|
@ -1,3 +1,60 @@
|
|||
2011-01-26 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* android
|
||||
android/default.properties
|
||||
android/.classpath
|
||||
android/proguard.cfg
|
||||
android/assets
|
||||
android/.project
|
||||
android/AndroidManifest.xml
|
||||
android/src
|
||||
android/src/pandroid
|
||||
android/src/pandroid/agent
|
||||
android/src/pandroid/agent/PandroidAgentTentacle.java
|
||||
android/src/pandroid/agent/PandroidAgent.java
|
||||
android/bin
|
||||
android/bin/pandroid
|
||||
android/bin/pandroid/agent
|
||||
android/bin/pandroid/agent/PandroidAgent$8.class
|
||||
android/bin/pandroid/agent/PandroidAgent$9.class
|
||||
android/bin/pandroid/agent/PandroidAgent.class
|
||||
android/bin/pandroid/agent/R$id.class
|
||||
android/bin/pandroid/agent/PandroidAgent$MyLocationListener.class
|
||||
android/bin/pandroid/agent/R$string.class
|
||||
android/bin/pandroid/agent/tentacle_client.class
|
||||
android/bin/pandroid/agent/R$attr.class
|
||||
android/bin/pandroid/agent/R.class
|
||||
android/bin/pandroid/agent/R$layout.class
|
||||
android/bin/pandroid/agent/PandroidAgent$1.class
|
||||
android/bin/pandroid/agent/PandroidAgent$2.class
|
||||
android/bin/pandroid/agent/PandroidAgent$3.class
|
||||
android/bin/pandroid/agent/PandroidAgent$4.class
|
||||
android/bin/pandroid/agent/R$drawable.class
|
||||
android/bin/pandroid/agent/PandroidAgent$5.class
|
||||
android/bin/pandroid/agent/PandroidAgent$6.class
|
||||
android/bin/pandroid/agent/PandroidAgent$7.class
|
||||
android/bin/resources.ap_
|
||||
android/bin/Copy of Copy of Pandroid Agent.apk
|
||||
android/bin/classes.dex
|
||||
android/res
|
||||
android/res/values
|
||||
android/res/values/strings.xml
|
||||
android/res/drawable-hdpi
|
||||
android/res/drawable-hdpi/logo.png
|
||||
android/res/drawable-hdpi/icon.png
|
||||
android/res/drawable-ldpi
|
||||
android/res/drawable-ldpi/icon.png
|
||||
android/res/drawable-mdpi
|
||||
android/res/drawable-mdpi/icon.png
|
||||
android/res/layout
|
||||
android/res/layout/main.xml
|
||||
android/gen
|
||||
android/gen/pandroid
|
||||
android/gen/pandroid/agent
|
||||
android/gen/pandroid/agent/R.java: Created the
|
||||
first android agent with report of battery level
|
||||
and basic GPS location coordinates report
|
||||
|
||||
2011-01-26 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* android
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Copy of Copy of Pandroid Agent</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="pandroid.agent"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".PandroidAgent"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
</manifest>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
pandora_agents/android/bin/pandroid/agent/PandroidAgent$MyLocationListener.class
Executable file
BIN
pandora_agents/android/bin/pandroid/agent/PandroidAgent$MyLocationListener.class
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,11 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-7
|
|
@ -0,0 +1,59 @@
|
|||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package pandroid.agent;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int icon=0x7f020000;
|
||||
public static final int logo=0x7f020001;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int agentNameInput=0x7f05000c;
|
||||
public static final int checkGpsReport=0x7f05000d;
|
||||
public static final int field1=0x7f050005;
|
||||
public static final int field2=0x7f050007;
|
||||
public static final int field3=0x7f050009;
|
||||
public static final int field4=0x7f05000b;
|
||||
public static final int fieldSummary=0x7f050003;
|
||||
public static final int groupRadioGpsReport=0x7f05000e;
|
||||
public static final int header=0x7f050001;
|
||||
public static final int intervalInput=0x7f05000a;
|
||||
public static final int lastContactInfo=0x7f050004;
|
||||
public static final int logo=0x7f050002;
|
||||
public static final int radioGpsCurrent=0x7f050010;
|
||||
public static final int radioGpsLast=0x7f05000f;
|
||||
public static final int reset=0x7f050012;
|
||||
public static final int serverAddrInput=0x7f050006;
|
||||
public static final int serverPortInput=0x7f050008;
|
||||
public static final int title=0x7f050000;
|
||||
public static final int update=0x7f050011;
|
||||
public static final int xml=0x7f050013;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int main=0x7f030000;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int agent=0x7f040007;
|
||||
public static final int app_name=0x7f040000;
|
||||
public static final int confTitle=0x7f040006;
|
||||
public static final int gpsCurrent=0x7f04000a;
|
||||
public static final int gpsLast=0x7f04000d;
|
||||
public static final int gpsMode=0x7f040009;
|
||||
public static final int gpsReport=0x7f040008;
|
||||
public static final int interval=0x7f040001;
|
||||
public static final int loading=0x7f04000e;
|
||||
public static final int reset=0x7f040003;
|
||||
public static final int serverAddr=0x7f040004;
|
||||
public static final int serverPort=0x7f040005;
|
||||
public static final int starStop=0x7f04000c;
|
||||
public static final int summary=0x7f04000b;
|
||||
public static final int update=0x7f040002;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
-optimizationpasses 5
|
||||
-dontusemixedcaseclassnames
|
||||
-dontskipnonpubliclibraryclasses
|
||||
-dontpreverify
|
||||
-verbose
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -0,0 +1,174 @@
|
|||
<?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>
|
||||
<RadioGroup android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="15dp"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/groupRadioGpsReport"
|
||||
android:layout_below="@id/checkGpsReport" >
|
||||
<RadioButton android:checked="false"
|
||||
android:text="@string/gpsLast"
|
||||
android:id="@+id/radioGpsLast"
|
||||
android:textSize="14dip"
|
||||
android:textColor="#bbbbbb"
|
||||
/>
|
||||
<RadioButton android:checked="false"
|
||||
android:text="@string/gpsCurrent"
|
||||
android:id="@+id/radioGpsCurrent"
|
||||
android:textSize="14dip"
|
||||
android:textColor="#bbbbbb"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</RadioGroup>
|
||||
<Button android:id="@+id/update"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/groupRadioGpsReport"
|
||||
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>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Pandroid Agent</string>
|
||||
<string name="interval">Interval:</string>
|
||||
<string name="update">Update conf.</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="gpsMode">GPS Mode</string>
|
||||
<string name="gpsCurrent">Current position (high battery cost)</string>
|
||||
<string name="summary">Current configuration:</string>
|
||||
<string name="starStop">Restart</string>
|
||||
<string name="gpsLast">Last known position</string>
|
||||
<string name="loading">Loading...</string>
|
||||
</resources>
|
|
@ -0,0 +1,657 @@
|
|||
package pandroid.agent;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.RadioButton;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnKeyListener;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.widget.Toast;
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.lang.Thread;
|
||||
|
||||
public class PandroidAgent extends Activity {
|
||||
Handler h = new Handler();
|
||||
|
||||
int defaultInterval = 300;
|
||||
String defaultServerPort = "41121";
|
||||
String defaultServerAddr = "10.0.2.2";
|
||||
String defaultAgentName = "pandroidAgent";
|
||||
String defaultGpsMode = "last"; // "last" or "current"
|
||||
String defaultGpsStatus = "disabled"; // "disabled" or "enabled"
|
||||
|
||||
boolean showLastXML = true;
|
||||
boolean contactError = false;
|
||||
|
||||
String lastGpsContactDateTime = "";
|
||||
Thread thread = new Thread();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.main);
|
||||
|
||||
// defaultGpsMode = "last";
|
||||
// String gpsMode = getSharedData("PANDROID_DATA", "gpsMode", defaultGpsMode, "string");
|
||||
//
|
||||
// if(gpsMode.equals(gpsMode)) {
|
||||
// LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
|
||||
// LocationListener mlocListener = new MyLocationListener();
|
||||
// //Use the LocationManager class to obtain GPS locations
|
||||
// mlocManager.requestLocationUpdates(
|
||||
// LocationManager.GPS_PROVIDER,
|
||||
// 0, // minTime in ms
|
||||
// 0, // minDistance in meters
|
||||
// mlocListener);
|
||||
// }
|
||||
|
||||
//resetValues();
|
||||
|
||||
initViews();
|
||||
|
||||
updateConf();
|
||||
|
||||
setCleanReturns();
|
||||
|
||||
setButtonEvents();
|
||||
|
||||
thread = new Thread(null, BGProcess, "Background");
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private Runnable BGProcess = new Runnable() {
|
||||
public void run() {
|
||||
backGroundOpps();
|
||||
}
|
||||
};
|
||||
|
||||
private void backGroundOpps() {
|
||||
h.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateLastContact();
|
||||
h.postDelayed(this, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void putSharedData(String preferenceName, String tokenName, String data, String type) {
|
||||
int mode = Activity.MODE_PRIVATE;
|
||||
SharedPreferences agentPreferences = getSharedPreferences(preferenceName, mode);
|
||||
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();
|
||||
}
|
||||
|
||||
private String getSharedData(String preferenceName, String tokenName, String defaultValue, String type) {
|
||||
int mode = Activity.MODE_PRIVATE;
|
||||
SharedPreferences agentPreferences = getSharedPreferences(preferenceName, mode);
|
||||
|
||||
if(type == "boolean") {
|
||||
boolean a = agentPreferences.getBoolean(tokenName, Boolean.parseBoolean(defaultValue));
|
||||
return new Boolean(a).toString();
|
||||
}
|
||||
else if(type == "float") {
|
||||
float a = agentPreferences.getFloat(tokenName, Float.parseFloat(defaultValue));
|
||||
return new Float(a).toString();
|
||||
}
|
||||
else if(type == "integer") {
|
||||
int a = agentPreferences.getInt(tokenName, Integer.parseInt(defaultValue));
|
||||
return new Integer(a).toString();
|
||||
}
|
||||
else if(type == "long") {
|
||||
long a = agentPreferences.getLong(tokenName, Long.parseLong(defaultValue));
|
||||
return new Long(a).toString();
|
||||
}
|
||||
else if(type == "string") {
|
||||
return agentPreferences.getString(tokenName, defaultValue);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private void setCleanReturns() {
|
||||
EditText intervalInput = (EditText) findViewById(R.id.intervalInput);
|
||||
intervalInput.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if(keyCode == 66) {
|
||||
EditText intervalInput = (EditText) findViewById(R.id.intervalInput);
|
||||
if(intervalInput.getText().toString().length() > 0) {
|
||||
intervalInput.setText(intervalInput.getText().toString().replaceAll("[\\r\\n]", ""));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
EditText serverAddrInput = (EditText) findViewById(R.id.serverAddrInput);
|
||||
serverAddrInput.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if(keyCode == 66) {
|
||||
EditText serverAddrInput = (EditText) findViewById(R.id.serverAddrInput);
|
||||
if(serverAddrInput.getText().toString().length() > 0) {
|
||||
serverAddrInput.setText(serverAddrInput.getText().toString().replaceAll("[\\r\\n]", ""));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
EditText agentNameInput = (EditText) findViewById(R.id.agentNameInput);
|
||||
agentNameInput.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if(keyCode == 66) {
|
||||
EditText agentNameInput = (EditText) findViewById(R.id.agentNameInput);
|
||||
if(agentNameInput.getText().toString().length() > 0) {
|
||||
agentNameInput.setText(agentNameInput.getText().toString().replaceAll("[\\r\\n]", ""));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setButtonEvents() {
|
||||
// Set update button events
|
||||
Button updateButton = (Button) findViewById(R.id.update);
|
||||
|
||||
updateButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
contactError = false;
|
||||
updateConf();
|
||||
contact();
|
||||
updateLastContact();
|
||||
hideKeyboard();
|
||||
}
|
||||
});
|
||||
|
||||
// Set reset button events
|
||||
Button resetButton = (Button) findViewById(R.id.reset);
|
||||
|
||||
resetButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
resetValues();
|
||||
initViews();
|
||||
updateConf();
|
||||
hideKeyboard();
|
||||
}
|
||||
});
|
||||
|
||||
// Set reset button events
|
||||
// Button startStopButton = (Button) findViewById(R.id.starStop);
|
||||
//
|
||||
// startStopButton.setOnClickListener(new OnClickListener() {
|
||||
// public void onClick(View view) {
|
||||
// thread.stop();
|
||||
// }
|
||||
// });
|
||||
|
||||
CheckBox checkGpsReport = (CheckBox) findViewById(R.id.checkGpsReport);
|
||||
|
||||
checkGpsReport.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
CheckBox checkGpsReport = (CheckBox) findViewById(R.id.checkGpsReport);
|
||||
RadioGroup gpsRadio = (RadioGroup) findViewById(R.id.groupRadioGpsReport);
|
||||
|
||||
if(checkGpsReport.isChecked()) {
|
||||
gpsRadio.setVisibility(gpsRadio.VISIBLE);
|
||||
putSharedData("PANDROID_DATA", "gpsStatus", "enabled", "string");
|
||||
}
|
||||
else {
|
||||
gpsRadio.setVisibility(gpsRadio.GONE);
|
||||
putSharedData("PANDROID_DATA", "gpsStatus", "disabled", "string");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void resetValues() {
|
||||
putSharedData("PANDROID_DATA", "serverAddr", defaultServerAddr, "string");
|
||||
putSharedData("PANDROID_DATA", "serverPort", defaultServerPort, "string");
|
||||
putSharedData("PANDROID_DATA", "interval", Integer.toString(defaultInterval), "integer");
|
||||
putSharedData("PANDROID_DATA", "agentName", defaultAgentName, "string");
|
||||
putSharedData("PANDROID_DATA", "latitude", "181", "float");
|
||||
putSharedData("PANDROID_DATA", "longitude", "181", "float");
|
||||
putSharedData("PANDROID_DATA", "gpsStatus", defaultGpsStatus, "string");
|
||||
putSharedData("PANDROID_DATA", "gpsMode", defaultGpsMode, "string");
|
||||
putSharedData("PANDROID_DATA", "lastContact", "-1", "long");
|
||||
}
|
||||
|
||||
private void updateConf() {
|
||||
EditText intervalInput = (EditText) findViewById(R.id.intervalInput);
|
||||
String interval = intervalInput.getText().toString().replace("\n", "");
|
||||
putSharedData("PANDROID_DATA", "interval", interval, "integer");
|
||||
|
||||
EditText serverAddrInput = (EditText) findViewById(R.id.serverAddrInput);
|
||||
String serverAddr = serverAddrInput.getText().toString();
|
||||
putSharedData("PANDROID_DATA", "serverAddr", serverAddr, "string");
|
||||
|
||||
EditText serverPortInput = (EditText) findViewById(R.id.serverPortInput);
|
||||
String serverPort = serverPortInput.getText().toString();
|
||||
putSharedData("PANDROID_DATA", "serverPort", serverPort, "string");
|
||||
|
||||
EditText agentNameInput = (EditText) findViewById(R.id.agentNameInput);
|
||||
String agentName = agentNameInput.getText().toString();
|
||||
putSharedData("PANDROID_DATA", "agentName", agentName, "string");
|
||||
|
||||
CheckBox checkGpsReport = (CheckBox) findViewById(R.id.checkGpsReport);
|
||||
|
||||
String gpsMode = "Disabled";
|
||||
if(checkGpsReport.isChecked()) {
|
||||
RadioButton radioGpsLast = (RadioButton) findViewById(R.id.radioGpsLast);
|
||||
if(radioGpsLast.isChecked()) {
|
||||
putSharedData("PANDROID_DATA", "gpsMode", "last", "string");
|
||||
gpsMode = "Last position";
|
||||
}
|
||||
else {
|
||||
putSharedData("PANDROID_DATA", "gpsMode", "current", "string");
|
||||
gpsMode = "Current position";
|
||||
}
|
||||
}
|
||||
|
||||
TextView summary = (TextView) this.findViewById(R.id.fieldSummary);
|
||||
summary.setText("Server: " + serverAddr + "\nPort: " + serverPort + "\nInterval: " + interval + " seconds\nAgent name: " + agentName + "\nGPS Mode: " + gpsMode);
|
||||
}
|
||||
|
||||
private void hideKeyboard() {
|
||||
EditText serverAddrInput = (EditText) findViewById(R.id.serverAddrInput);
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(serverAddrInput.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
private void updateLastContact(){
|
||||
//long lastContact = Long.parseLong("5");
|
||||
long lastContact = Long.parseLong(getSharedData("PANDROID_DATA", "lastContact", "-1", "long"));
|
||||
|
||||
if(lastContact == -1) {
|
||||
contact();
|
||||
}
|
||||
|
||||
updateValues();
|
||||
|
||||
Date date = new Date();
|
||||
long timestamp = date.getTime() / 1000;
|
||||
long timeAgo = timestamp - lastContact;
|
||||
|
||||
int interval = Integer.parseInt(getSharedData("PANDROID_DATA", "interval", Integer.toString(defaultInterval), "integer"));
|
||||
|
||||
if(timeAgo >= interval) {
|
||||
contact();
|
||||
timeAgo = 0;
|
||||
}
|
||||
|
||||
if(contactError) {
|
||||
changeContactInfo("Contact error", "#FF0000");
|
||||
}
|
||||
else {
|
||||
String stringAgo = timeAgo + " seconds ago.";
|
||||
if(timeAgo == 0) {
|
||||
stringAgo = "Now.";
|
||||
}
|
||||
changeContactInfo("Last Contact: " + stringAgo, "#00FF00");
|
||||
}
|
||||
|
||||
TextView xml = (TextView) this.findViewById(R.id.xml);
|
||||
if(showLastXML) {
|
||||
String lastXML = getSharedData("PANDROID_DATA", "lastXML", "[no data]", "string");
|
||||
xml.setText("Last XML builded: \n\n" + lastXML);
|
||||
}
|
||||
else {
|
||||
xml.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void changeContactInfo(String msg, String colorCode) {
|
||||
TextView lastContactInfo = (TextView) this.findViewById(R.id.lastContactInfo);
|
||||
lastContactInfo.setTextColor(Color.parseColor(colorCode));
|
||||
lastContactInfo.setText(msg);
|
||||
|
||||
}
|
||||
|
||||
private void updateSharedData() {
|
||||
TextView summary = (TextView) this.findViewById(R.id.fieldSummary);
|
||||
String serverAddr = getSharedData("PANDROID_DATA", "serverAddr", "[no data]", "string");
|
||||
String serverPort = getSharedData("PANDROID_DATA", "serverPort", "[no data]", "string");
|
||||
String interval = getSharedData("PANDROID_DATA", "interval", "300", "integer");
|
||||
String agentName = getSharedData("PANDROID_DATA", "agentName", "[no data]", "string");
|
||||
summary.setText("Server: " + serverAddr + "\nPort: " + serverPort + "\nInterval: " + interval + "\nAgent name: " + agentName);
|
||||
}
|
||||
|
||||
private void contact(){
|
||||
Date date = new Date();
|
||||
|
||||
putSharedData("PANDROID_DATA", "lastContact", Long.toString(date.getTime() / 1000), "long");
|
||||
|
||||
// Keep lastXML sended if is not empty (empty means error sending it)
|
||||
String lastXML = buildXML();
|
||||
|
||||
if(!lastXML.equals("")) {
|
||||
putSharedData("PANDROID_DATA", "lastXML", lastXML, "string");
|
||||
}
|
||||
|
||||
updateValues();
|
||||
}
|
||||
|
||||
private void initViews(){
|
||||
// Init form values
|
||||
EditText serverAddrInput = (EditText) findViewById(R.id.serverAddrInput);
|
||||
serverAddrInput.setText(getSharedData("PANDROID_DATA", "serverAddr", defaultServerAddr, "string"));
|
||||
|
||||
EditText serverPortInput = (EditText) findViewById(R.id.serverPortInput);
|
||||
serverPortInput.setText(getSharedData("PANDROID_DATA", "serverPort", defaultServerPort, "string"));
|
||||
|
||||
EditText intervalInput = (EditText) findViewById(R.id.intervalInput);
|
||||
int interval = Integer.parseInt(getSharedData("PANDROID_DATA", "interval", Integer.toString(defaultInterval), "integer"));
|
||||
intervalInput.setText(Integer.toString(interval));
|
||||
|
||||
EditText agentNameInput = (EditText) findViewById(R.id.agentNameInput);
|
||||
agentNameInput.setText(getSharedData("PANDROID_DATA", "agentName", defaultAgentName, "string"));
|
||||
|
||||
CheckBox checkGpsReport = (CheckBox) findViewById(R.id.checkGpsReport);
|
||||
|
||||
String gpsStatus = getSharedData("PANDROID_DATA", "gpsStatus", defaultGpsStatus, "string");
|
||||
boolean gpsEnabled = gpsStatus.equals("enabled");
|
||||
checkGpsReport.setChecked(gpsEnabled);
|
||||
|
||||
RadioGroup gpsRadio = (RadioGroup) findViewById(R.id.groupRadioGpsReport);
|
||||
|
||||
if(gpsEnabled) {
|
||||
gpsRadio.setVisibility(gpsRadio.VISIBLE);
|
||||
}
|
||||
else {
|
||||
gpsRadio.setVisibility(gpsRadio.GONE);
|
||||
}
|
||||
|
||||
RadioButton radioGpsCurrent = (RadioButton) findViewById(R.id.radioGpsCurrent);
|
||||
RadioButton radioGpsLast = (RadioButton) findViewById(R.id.radioGpsLast);
|
||||
|
||||
|
||||
if(getSharedData("PANDROID_DATA", "gpsMode", defaultGpsMode, "string").equals("current")) {
|
||||
radioGpsCurrent.setChecked(true);
|
||||
}
|
||||
else {
|
||||
radioGpsLast.setChecked(true);
|
||||
}
|
||||
|
||||
updateValues();
|
||||
}
|
||||
|
||||
private String buildXML(){
|
||||
String buffer = "";
|
||||
String gpsData = "";
|
||||
buffer += "<?xml version='1.0' encoding='utf-8'?>\n";
|
||||
|
||||
String latitude = getSharedData("PANDROID_DATA", "latitude", "181", "float");
|
||||
String longitude = getSharedData("PANDROID_DATA", "longitude", "181", "float");
|
||||
|
||||
if(!latitude.equals("181.0") && !longitude.equals("181.0")) {
|
||||
gpsData = " latitude='" + latitude + "' longitude='" + longitude + "'";
|
||||
}
|
||||
|
||||
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' interval='"+ interval +"' version='3.2RC1(Build 101103)' timestamp='" + getHumanDateTime(-1) + "' agent_name='" + agentName + "' timezone_offset='0'" + gpsData +">\n";
|
||||
|
||||
// Modules
|
||||
buffer += buildmoduleXML("battery_level", "The actually device battery level", "generic_data", getSharedData("PANDROID_DATA", "batteryLevel", "-1", "integer"));
|
||||
//buffer += buildmoduleXML("last_gps_contact", "Datetime of the last geo-location contact", "generic_data", lastGpsContactDateTime);
|
||||
|
||||
// End_Modules
|
||||
|
||||
buffer += "</agent_data>";
|
||||
|
||||
String destFileName = agentName + "." + System.currentTimeMillis() + ".data";
|
||||
|
||||
writeFile(destFileName, buffer);
|
||||
|
||||
String[] tentacleData = {
|
||||
"-a",
|
||||
getSharedData("PANDROID_DATA", "serverAddr", "", "string"),
|
||||
"-p",
|
||||
defaultServerPort,
|
||||
"-v",
|
||||
"/data/data/pandroid.agent/files/" + destFileName
|
||||
};
|
||||
|
||||
int tentacleRet = new tentacle_client().tentacle_client(tentacleData);
|
||||
|
||||
if(tentacleRet == 0) {
|
||||
contactError = false;
|
||||
}
|
||||
else {
|
||||
contactError = true;
|
||||
buffer = "";
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
private String buildmoduleXML(String name, String description, String type, String data){
|
||||
String buffer = "";
|
||||
buffer += " <module>\n";
|
||||
buffer += " <name><![CDATA[" + name + "]]></name>\n";
|
||||
buffer += " <description><![CDATA[" + description + "]]></description>\n";
|
||||
buffer += " <type><![CDATA[" + type + "]]></type>\n";
|
||||
buffer += " <data><![CDATA[" + data + "]]></data>\n";
|
||||
buffer += " </module>\n";
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Get human date time from unixtime in milliseconds.
|
||||
// If unixtime = -1 is returned the current datetime
|
||||
////////////////////////////////////////////////////////////
|
||||
private String getHumanDateTime(long unixtime){
|
||||
Calendar dateTime = Calendar.getInstance();
|
||||
if(unixtime != -1) {
|
||||
dateTime.setTimeInMillis(unixtime);
|
||||
}
|
||||
String humanDateTime;
|
||||
|
||||
humanDateTime = dateTime.get(Calendar.YEAR) + "/";
|
||||
|
||||
int month = dateTime.get(Calendar.MONTH) + 1;
|
||||
if(month < 10) {
|
||||
humanDateTime += "0";
|
||||
}
|
||||
humanDateTime += month + "/";
|
||||
|
||||
int day = dateTime.get(Calendar.DAY_OF_MONTH);
|
||||
if(day < 10) {
|
||||
humanDateTime += "0";
|
||||
}
|
||||
humanDateTime += day + " ";
|
||||
|
||||
int hour = dateTime.get(Calendar.HOUR_OF_DAY);
|
||||
if(hour < 10) {
|
||||
humanDateTime += "0";
|
||||
}
|
||||
humanDateTime += hour + ":";
|
||||
|
||||
int minute = dateTime.get(Calendar.MINUTE);
|
||||
if(minute < 10) {
|
||||
humanDateTime += "0";
|
||||
}
|
||||
humanDateTime += minute + ":";
|
||||
|
||||
int second = dateTime.get(Calendar.SECOND);
|
||||
if(second < 10) {
|
||||
humanDateTime += "0";
|
||||
}
|
||||
humanDateTime += second;
|
||||
|
||||
return humanDateTime;
|
||||
}
|
||||
|
||||
|
||||
private void showToast (String msg) {
|
||||
Context context = getApplicationContext();
|
||||
int duration = Toast.LENGTH_SHORT;
|
||||
|
||||
Toast toast = Toast.makeText(context, msg, duration);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Getting values from device functions
|
||||
///////////////////////////////////////////
|
||||
|
||||
private void gpsLocation() {
|
||||
// Starts with GPS, if no GPS then gets network location
|
||||
|
||||
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
List<String> providers = lm.getProviders(true);
|
||||
|
||||
/* Loop over the array backwards, and if you get an accurate location, then break out the loop*/
|
||||
Location loc = null;
|
||||
|
||||
for (int i=providers.size()-1; i>=0; i--) {
|
||||
loc = lm.getLastKnownLocation(providers.get(i));
|
||||
if (loc != null) break;
|
||||
}
|
||||
|
||||
if (loc != null) {
|
||||
//if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) {
|
||||
lastGpsContactDateTime = getHumanDateTime(-1);
|
||||
//}
|
||||
putSharedData("PANDROID_DATA", "latitude", new Double(loc.getLatitude()).toString(), "float");
|
||||
putSharedData("PANDROID_DATA", "longitude", new Double(loc.getLongitude()).toString(), "float");
|
||||
}
|
||||
else {
|
||||
putSharedData("PANDROID_DATA", "latitude", "181", "float");
|
||||
putSharedData("PANDROID_DATA", "longitude", "181", "float");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void batteryLevel() {
|
||||
BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
context.unregisterReceiver(this);
|
||||
int rawlevel = intent.getIntExtra("level", -1);
|
||||
int scale = intent.getIntExtra("scale", -1);
|
||||
if (rawlevel >= 0 && scale > 0) {
|
||||
putSharedData("PANDROID_DATA", "batteryLevel", new Integer((rawlevel * 100) / scale).toString(), "integer");
|
||||
}
|
||||
}
|
||||
};
|
||||
IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
registerReceiver(batteryLevelReceiver, batteryLevelFilter);
|
||||
}
|
||||
|
||||
private void updateValues() {
|
||||
batteryLevel();
|
||||
String gpsMode = getSharedData("PANDROID_DATA", "gpsMode", defaultGpsMode, "string");
|
||||
|
||||
if(gpsMode.equals("last")) {
|
||||
gpsLocation();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFile(String fileName, String textToWrite) {
|
||||
try { // catches IOException below
|
||||
FileOutputStream fOut = openFileOutput(fileName,
|
||||
MODE_WORLD_READABLE);
|
||||
OutputStreamWriter osw = new OutputStreamWriter(fOut);
|
||||
|
||||
// Write the string to the file
|
||||
osw.write(textToWrite);
|
||||
/* ensure that everything is
|
||||
* really written out and close */
|
||||
osw.flush();
|
||||
osw.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String readFile(String fileName) {
|
||||
String readString = "";
|
||||
try { // catches IOException below
|
||||
FileInputStream fIn = openFileInput(fileName);
|
||||
InputStreamReader isr = new InputStreamReader(fIn);
|
||||
/* Prepare a char-Array that will
|
||||
* hold the chars we read back in. */
|
||||
char[] inputBuffer = new char[100];
|
||||
// Fill the Buffer with data from the file
|
||||
isr.read(inputBuffer);
|
||||
// Transform the chars to a String
|
||||
readString = new String(inputBuffer);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
|
||||
return readString;
|
||||
}
|
||||
|
||||
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) {
|
||||
putSharedData("PANDROID_DATA", "latitude", "181", "float");
|
||||
putSharedData("PANDROID_DATA", "longitude", "181", "float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
|
||||
}/* End of Class MyLocationListener */
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
package pandroid.agent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
class tentacle_client {
|
||||
|
||||
// Return 0 when success, -1 when error
|
||||
public int tentacle_client(String args[]) {
|
||||
|
||||
int port = 41121;
|
||||
String send = null;
|
||||
String serverResponse = null;
|
||||
String address = "127.0.0.1";
|
||||
String data = "";
|
||||
String parameter = "";
|
||||
String filePath = null;
|
||||
boolean verbose = false;
|
||||
File file = new File("");
|
||||
|
||||
for (int i=0;i<args.length;i++) {
|
||||
if(i == (args.length - 1)) {
|
||||
filePath = args[i];
|
||||
} else {
|
||||
// Get the param if is -* format or empty string otherwise
|
||||
String last_parameter = parameter;
|
||||
parameter = isParameter(args[i]);
|
||||
|
||||
// If is not -* param check the previous param
|
||||
if(parameter.equals("")) {
|
||||
if(last_parameter.equals("-a")) {
|
||||
address = args[i];
|
||||
}
|
||||
else if(last_parameter.equals("-p")) {
|
||||
port = Integer.parseInt(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// The solo params are checked otherwise
|
||||
if(parameter.equals("-v")) {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(filePath == null) {
|
||||
getError("Incorrect parameters. File path is necessary.");
|
||||
}
|
||||
|
||||
getInfo("\n*** Starting tentacle client ***\n",verbose);
|
||||
|
||||
Socket socketCliente = null;
|
||||
try {
|
||||
socketCliente = new Socket(address, port);
|
||||
} catch (UnknownHostException e) {
|
||||
getError("Host don't exists");
|
||||
return -1;
|
||||
} catch (IOException e) {
|
||||
getError("Could not connect: The host is down");
|
||||
return -1;
|
||||
}
|
||||
|
||||
DataOutputStream serverOutput = null;
|
||||
|
||||
try {
|
||||
serverOutput = new DataOutputStream(socketCliente.getOutputStream());
|
||||
} catch (IOException e1) {
|
||||
getError("Could not get Data output stream");
|
||||
}
|
||||
|
||||
BufferedReader serverInput = null;
|
||||
|
||||
try {
|
||||
serverInput = new BufferedReader(new InputStreamReader(socketCliente.getInputStream()));
|
||||
} catch (IOException e1) {
|
||||
getError("Could not get Buffered reader");
|
||||
}
|
||||
|
||||
try {
|
||||
file = new File (filePath);
|
||||
FileReader fr = new FileReader (file);
|
||||
BufferedReader br = new BufferedReader(fr);
|
||||
|
||||
getInfo("Reading the file '" + file.getName() + "' content...\n", verbose);
|
||||
// Reading the file
|
||||
String line;
|
||||
while((line=br.readLine())!=null)
|
||||
data += line + '\n';
|
||||
} catch (IOException e) {
|
||||
getError("Could not get the file");
|
||||
}
|
||||
|
||||
getInfo("*** Start of transference ***\n",verbose);
|
||||
// Send the file name and length
|
||||
try {
|
||||
send = "SEND <" + file.getName() + "> SIZE " + Integer.toString(data.length()) + '\n';
|
||||
getInfo("Client -> Server: " + send, verbose);
|
||||
serverOutput.writeBytes(send);
|
||||
} catch (IOException e) {
|
||||
getError("Could not write on server");
|
||||
}
|
||||
try {
|
||||
serverResponse = serverInput.readLine();
|
||||
} catch (IOException e) {
|
||||
getError("Could not get server response");
|
||||
}
|
||||
|
||||
getInfo("Server -> Client: " + serverResponse + "\n", verbose);
|
||||
if (serverResponse.equals("SEND OK")) {
|
||||
try {
|
||||
getInfo("Client -> Server: [file data]\n", verbose);
|
||||
serverOutput.writeBytes(data);
|
||||
} catch (IOException e) {
|
||||
getError("Could not write on server");
|
||||
}
|
||||
try {
|
||||
serverResponse = serverInput.readLine();
|
||||
} catch (IOException e) {
|
||||
getError("Could not get server response");
|
||||
}
|
||||
|
||||
getInfo("Server -> Client: " + serverResponse + "\n", verbose);
|
||||
if (serverResponse.equals("SEND OK")) {
|
||||
try {
|
||||
send = "QUIT\n";
|
||||
getInfo("Client -> Server: " + send, verbose);
|
||||
serverOutput.writeBytes("QUIT\n");
|
||||
} catch (IOException e) {
|
||||
getError("Could not write on server");
|
||||
}
|
||||
getInfo("*** End of transference ***\n", verbose);
|
||||
}
|
||||
else {
|
||||
getError("Bad server response, execution aborted.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
getError("Bad server response, execution aborted.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private String isParameter(String str) {
|
||||
if(str.equals("-a") || str.equals("-p") || str.equals("-v")) {
|
||||
return str;
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void getError(String error_str) {
|
||||
log("[ERROR] " + error_str + '\n');
|
||||
}
|
||||
|
||||
private void getInfo(String error_str, boolean verbose) {
|
||||
if(verbose) {
|
||||
log("[INFO] " + error_str + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
private void log (String msg) {
|
||||
//Context context = getApplicationContext();
|
||||
//int duration = Toast.LENGTH_SHORT;
|
||||
|
||||
//Toast toast = Toast.makeText(context, msg, duration);
|
||||
//toast.show();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue