From 2889bf9b4b927b7056eb2ec01c91ebc7bbb58af5 Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Mon, 10 Oct 2011 16:19:38 -0700 Subject: [PATCH] send new log messages to server on each HTTP request; notify server of changes in device status (currently power/battery state) --- AndroidManifest.xml | 17 +++- server/php/EnvayaSMS.php | 24 +++++- server/php/example/log/.gitignore | 1 + server/php/example/www/index.php | 14 ++++ server/php/example/www/test.html | 22 ++++- src/org/envaya/sms/App.java | 80 +++++++++++++++++-- src/org/envaya/sms/Outbox.java | 11 ++- .../sms/receiver/DeviceStatusReceiver.java | 53 ++++++++++++ src/org/envaya/sms/task/HttpTask.java | 48 ++++++++--- src/org/envaya/sms/ui/Main.java | 13 ++- src/org/envaya/sms/ui/PendingMessages.java | 7 ++ 11 files changed, 259 insertions(+), 31 deletions(-) create mode 100644 server/php/example/log/.gitignore create mode 100755 src/org/envaya/sms/receiver/DeviceStatusReceiver.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f0e26dd..58b0125 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="14" + android:versionName="2.0.1"> @@ -105,17 +105,26 @@ - + + + + + + + + + + - + \ No newline at end of file diff --git a/server/php/EnvayaSMS.php b/server/php/EnvayaSMS.php index d2ff8e9..5580050 100755 --- a/server/php/EnvayaSMS.php +++ b/server/php/EnvayaSMS.php @@ -11,12 +11,18 @@ class EnvayaSMS const ACTION_INCOMING = 'incoming'; const ACTION_OUTGOING = 'outgoing'; const ACTION_SEND_STATUS = 'send_status'; + const ACTION_DEVICE_STATUS = 'device_status'; const ACTION_TEST = 'test'; const STATUS_QUEUED = 'queued'; const STATUS_FAILED = 'failed'; const STATUS_SENT = 'sent'; + const DEVICE_STATUS_POWER_CONNECTED = "power_connected"; + const DEVICE_STATUS_POWER_DISCONNECTED = "power_disconnected"; + const DEVICE_STATUS_BATTERY_LOW = "battery_low"; + const DEVICE_STATUS_BATTERY_OKAY = "battery_okay"; + const MESSAGE_TYPE_SMS = 'sms'; const MESSAGE_TYPE_MMS = 'mms'; @@ -49,11 +55,13 @@ class EnvayaSMS_Request public $version; public $phone_number; + public $log; function __construct() { $this->version = $_POST['version']; $this->phone_number = $_POST['phone_number']; + $this->log = @$_POST['log']; } function get_action() @@ -77,6 +85,8 @@ class EnvayaSMS_Request return new EnvayaSMS_Action_SendStatus($this); case EnvayaSMS::ACTION_TEST: return new EnvayaSMS_Action_Test($this); + case EnvayaSMS::ACTION_DEVICE_STATUS: + return new EnvayaSMS_Action_DeviceStatus($this); default: return new EnvayaSMS_Action($this); } @@ -247,4 +257,16 @@ class EnvayaSMS_Action_SendStatus extends EnvayaSMS_Action $this->id = $_POST['id']; $this->error = $_POST['error']; } -} \ No newline at end of file +} + +class EnvayaSMS_Action_DeviceStatus extends EnvayaSMS_Action +{ + public $status; // EnvayaSMS::DEVICE_STATUS_* values + + function __construct($request) + { + parent::__construct($request); + $this->type = EnvayaSMS::ACTION_DEVICE_STATUS; + $this->status = $_POST['status']; + } +} diff --git a/server/php/example/log/.gitignore b/server/php/example/log/.gitignore new file mode 100644 index 0000000..bf0824e --- /dev/null +++ b/server/php/example/log/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/server/php/example/www/index.php b/server/php/example/www/index.php index ff3c80c..510895f 100755 --- a/server/php/example/www/index.php +++ b/server/php/example/www/index.php @@ -22,6 +22,16 @@ if (!isset($password) || !$request->is_validated($password)) return; } +// append to EnvayaSMS app log +$app_log = $request->log; +if ($app_log) +{ + $log_file = dirname(__DIR__)."/log/sms_".preg_replace('#[^\w]#', '', $request->phone_number).".log"; + $f = fopen($log_file, "a"); + fwrite($f, $app_log); + fclose($f); +} + $action = $request->get_action(); switch ($action->type) @@ -79,6 +89,10 @@ switch ($action->type) echo "invalid id"; } return; + case EnvayaSMS::ACTION_DEVICE_STATUS: + error_log("device_status = {$action->status}"); + echo "OK"; + return; case EnvayaSMS::ACTION_TEST: echo "OK"; return; diff --git a/server/php/example/www/test.html b/server/php/example/www/test.html index b8e5bd0..4023439 100755 --- a/server/php/example/www/test.html +++ b/server/php/example/www/test.html @@ -1,6 +1,6 @@ - +EnvayaSMS Request Simulator