Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new pull request #3

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4130593
polling
niryariv Jan 15, 2011
aee1061
initial import of polling code
niryariv Jan 15, 2011
8e31033
new icon
niryariv Jan 15, 2011
ec1dc62
simplify polling UI to use fixed, 15 min intervals
niryariv Jan 15, 2011
2089450
cleanup home screen text
niryariv Jan 16, 2011
3ed1958
add a poll=true parameter
niryariv Jan 16, 2011
448eafe
Move post-parse sms sending to TargetUrlRequest
niryariv Jan 18, 2011
9473ab1
use POST in http requests; use different url for outgoing sms; poll f…
Sep 11, 2011
fc6cda4
do http requests in AsyncTask so they don't freeze the UI thread; imp…
Sep 12, 2011
8f15a8c
add menu with options to test server connection, or edit settings
Sep 12, 2011
d5b9734
fix null pointer exception; remove dependency on Base64 for android 1…
Sep 12, 2011
cb8d95e
PHP server library with example implementation; add 'check now' butto…
Sep 12, 2011
aff22e5
use string status codes instead of integers
Sep 13, 2011
0a0f50a
fix comments for php server example
Sep 13, 2011
da334a0
remove test action to simplify server implementation; add icons from …
Sep 13, 2011
307f354
add help screen
Sep 13, 2011
2911111
keep messages waiting to be sent in memory; if forwarding fails (in e…
Sep 13, 2011
d29e7b2
start alarm to poll for outgoing messages when phone boots; add optio…
Sep 13, 2011
e4cea3b
use alarm to schedule retries; fix bug where sms notfications were dr…
Sep 13, 2011
bead453
set phone number and api version as regular post fields instead of cu…
Sep 13, 2011
e535266
instead of deleting messages from inbox, prevent them from getting th…
Sep 13, 2011
e79fe7c
refactoring
Sep 13, 2011
61d24b2
add setting to enable/disable sms gateway
Sep 13, 2011
41141fa
add menu option to forward existing messages from inbox (delivered wh…
Sep 14, 2011
0071efd
improve ForwardInbox with help from http://www.marvinlabs.com/2010/10…
Sep 14, 2011
2f22c29
github generated gh-pages branch
youngj Sep 15, 2011
e78598c
refactor App to subclass Application; retain log messages in App clas…
Sep 15, 2011
46710c2
organize code into subpackages
Sep 16, 2011
60d4941
launching Main activity on boot is no longer necessary
Sep 16, 2011
d994b10
support for incoming MMS
Sep 18, 2011
72a893e
Merge branch 'gh-pages' of github.com:youngj/KalSMS
Sep 18, 2011
7bc88cf
updated readme
Sep 18, 2011
e834488
avoid exceeding Android limit of 100 outgoing SMS/app/hour; allow eff…
Sep 18, 2011
d720412
most README content moved to http://youngj.github.com/KalSMS/
Sep 19, 2011
430aeca
enable user to change wifi sleep policy on kalsms settings page for c…
Sep 19, 2011
3357de7
assume http:// scheme for server URLs
Sep 19, 2011
eb80837
add test mode to allow testing KalSMS on a phone that is also being u…
Sep 19, 2011
a793a5f
use http connection pooling to improve performance (especially over ssl)
Sep 20, 2011
9a574b3
add foreground service to keep App in memory (otherwise rate-limiting…
Sep 20, 2011
9440fdb
android's ForegroundService example code is surprisingly buggy
Sep 20, 2011
4b0010f
display version number
Sep 20, 2011
687400f
use kalsms version code in http requests
Sep 20, 2011
b6a372d
avoid forwarding sms from network; unregister mms observer when kalsm…
Sep 21, 2011
dbf3536
update url in readme
Sep 21, 2011
73bc3c9
MMS fixes: prevent httpclient from using transfer-encoding: chunked s…
Sep 22, 2011
7df89cd
rename to EnvayaSMS; add icon
Sep 22, 2011
1cf69e8
update links
Sep 23, 2011
6384942
handle sending and receiving multipart sms messages > 160 chars
Sep 24, 2011
986b50f
fix bug where outgoing sms would be cut off if they contain xml entities
Sep 25, 2011
bf14f23
fix encoding problem for post requests, make test a separate action
Sep 27, 2011
03d5f55
update php server library and example
Sep 27, 2011
faffc6c
don't request delivery reports but leave option open in future; fix b…
Sep 28, 2011
3108512
keep backlogged outgoing messages in priority queue; allow server to …
Sep 28, 2011
1081f57
automatic failover between wifi/mobile if server cannot be reached; s…
Sep 29, 2011
d7f803e
add PendingMessages activity for viewing/retrying/deleting pending me…
Oct 1, 2011
cf1deec
queue incoming messages like outgoing messages
Oct 1, 2011
dedfdb5
improve performance of displaying log in Main activity
Oct 1, 2011
79ec4c1
add note about local.properties and sdk.dir to README
Oct 4, 2011
af1f8af
add html page for simulating EnvayaSMS requests
Oct 9, 2011
f253f54
update license and readme files for request simulator
Oct 9, 2011
2889bf9
send new log messages to server on each HTTP request; notify server o…
Oct 10, 2011
f430ddb
set http user-agent header
Nov 13, 2011
22f8c26
add settings screen for ignored phone numbers; allow user to specify …
Nov 26, 2011
c18a28b
enable long polling - increase socket timeout, start only one PollerT…
Nov 30, 2011
6f19970
increment version to 2.0.4
Nov 30, 2011
d93ff76
update httpserver submodule to latest version
youngj Mar 15, 2012
f53ccc3
add support for incoming call notifications; fix intermittent NullPoi…
youngj Mar 16, 2012
239ee1f
version 3.0 - real-time AMQP connections; change server API format f…
youngj Apr 4, 2012
9d65fc1
remove stray references to telerivet
youngj Apr 4, 2012
69a05ac
remove code added for debugging
youngj Apr 4, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor App to subclass Application; retain log messages in App clas…
…s so they can be shown even if Main activity is inactive or gets reset
Jesse Young committed Sep 15, 2011
commit e78598c91960a66856995f3f3a7ee7e3bc7cc5ec
14 changes: 12 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -5,14 +5,17 @@
android:versionName="1.0">

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<application android:name="org.envaya.kalsms.App"
android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -27,12 +30,19 @@
</activity>


<receiver android:name=".IncomingMessageForwarder">
<receiver android:name=".SMSReceiver">
<intent-filter android:priority="101">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

<receiver android:name=".MMSReceiver">
<intent-filter android:priority="101">
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>

<receiver android:name=".MessageStatusNotifier">
</receiver>

103 changes: 68 additions & 35 deletions src/org/envaya/kalsms/App.java
Original file line number Diff line number Diff line change
@@ -2,20 +2,24 @@

import android.app.Activity;
import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.telephony.SmsManager;
import android.text.SpannableStringBuilder;
import android.util.Log;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.message.BasicNameValuePair;

public class App {

public final class App extends Application {
public static final String ACTION_OUTGOING = "outgoing";
public static final String ACTION_INCOMING = "incoming";
public static final String ACTION_SEND_STATUS = "send_status";
@@ -24,24 +28,18 @@ public class App {
public static final String STATUS_SENT = "sent";
public static final String LOG_NAME = "KALSMS";
public static final String LOG_INTENT = "org.envaya.kalsms.LOG";
private static App app;

public static final int MAX_DISPLAYED_LOG = 15000;
public static final int LOG_TIMESTAMP_INTERVAL = 60000;

private long lastLogTime = 0;
private SpannableStringBuilder displayedLog = new SpannableStringBuilder();
private Map<String, IncomingMessage> incomingSmsMap = new HashMap<String, IncomingMessage>();
private Map<String, OutgoingMessage> outgoingSmsMap = new HashMap<String, OutgoingMessage>();

public Context context;
public SharedPreferences settings;

protected App(Context context) {
this.context = context;
this.settings = PreferenceManager.getDefaultSharedPreferences(context);
}

public static App getInstance(Context context) {
if (app == null) {
app = new App(context);
}
return app;
public SharedPreferences getSettings()
{
return PreferenceManager.getDefaultSharedPreferences(this);
}

public void checkOutgoingMessages()
@@ -56,11 +54,11 @@ public void checkOutgoingMessages()
}

public void setOutgoingMessageAlarm() {
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
0,
new Intent(context, OutgoingMessagePoller.class),
new Intent(this, OutgoingMessagePoller.class),
0);

alarm.cancel(pendingIntent);
@@ -91,33 +89,33 @@ public String getDisplayString(String str) {
}

public String getServerUrl() {
return settings.getString("server_url", "");
return getSettings().getString("server_url", "");
}

public String getPhoneNumber() {
return settings.getString("phone_number", "");
return getSettings().getString("phone_number", "");
}

public int getOutgoingPollSeconds() {
return Integer.parseInt(settings.getString("outgoing_interval", "0"));
return Integer.parseInt(getSettings().getString("outgoing_interval", "0"));
}

public boolean getLaunchOnBoot() {
return settings.getBoolean("launch_on_boot", false);
return getSettings().getBoolean("launch_on_boot", false);
}

public boolean isEnabled()
{
return settings.getBoolean("enabled", false);
return getSettings().getBoolean("enabled", false);
}

public boolean getKeepInInbox()
{
return settings.getBoolean("keep_in_inbox", false);
return getSettings().getBoolean("keep_in_inbox", false);
}

public String getPassword() {
return settings.getString("password", "");
return getSettings().getString("password", "");
}

private void notifyStatus(OutgoingMessage sms, String status, String errorMessage) {
@@ -134,16 +132,16 @@ private void notifyStatus(OutgoingMessage sms, String status, String errorMessag
String smsDesc = sms.getLogName();

if (serverId != null) {
app.log("Notifying server " + smsDesc + " " + logMessage);
log("Notifying server " + smsDesc + " " + logMessage);

new HttpTask(app,
new HttpTask(this,
new BasicNameValuePair("id", serverId),
new BasicNameValuePair("status", status),
new BasicNameValuePair("error", errorMessage),
new BasicNameValuePair("action", App.ACTION_SEND_STATUS)
).execute();
} else {
app.log(smsDesc + " " + logMessage);
log(smsDesc + " " + logMessage);
}
}

@@ -245,7 +243,7 @@ public synchronized void forwardToServer(IncomingMessage sms) {

incomingSmsMap.put(id, sms);

app.log("Received SMS from " + sms.getFrom());
log("Received SMS from " + sms.getFrom());

sms.tryForwardToServer();
}
@@ -264,16 +262,51 @@ public synchronized void retryOutgoingMessage(String id) {
}
}

public void debug(String msg) {
public void debug(String msg) {
Log.d(LOG_NAME, msg);
}

public void log(String msg) {
Log.d(LOG_NAME, msg);
public void log(CharSequence msg)
{
Log.d(LOG_NAME, msg.toString());

// prevent displayed log from growing too big
int length = displayedLog.length();
if (length > MAX_DISPLAYED_LOG)
{
int startPos = length - MAX_DISPLAYED_LOG * 3 / 4;

for (int cur = startPos; cur < startPos + 100 && cur < length; cur++)
{
if (displayedLog.charAt(cur) == '\n')
{
startPos = cur;
break;
}
}

displayedLog.replace(0, startPos, "[Older log messages not shown]\n");
}

// display a timestamp in the log occasionally
long logTime = SystemClock.elapsedRealtime();
if (logTime - lastLogTime > LOG_TIMESTAMP_INTERVAL)
{
Date date = new Date();
displayedLog.append("[" + DateFormat.getTimeInstance().format(date) + "]\n");
lastLogTime = logTime;
}

displayedLog.append(msg);
displayedLog.append("\n");

Intent broadcast = new Intent(App.LOG_INTENT);
broadcast.putExtra("message", msg);
context.sendBroadcast(broadcast);
sendBroadcast(broadcast);
}

public CharSequence getDisplayedLog()
{
return displayedLog;
}

public void logError(Throwable ex) {
2 changes: 1 addition & 1 deletion src/org/envaya/kalsms/BootReceiver.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
App app = App.getInstance(context.getApplicationContext());
App app = (App)context.getApplicationContext();
if (!app.isEnabled())
{
return;
2 changes: 1 addition & 1 deletion src/org/envaya/kalsms/ForwardInbox.java
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public class ForwardInbox extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

app = App.getInstance(getApplicationContext());
app = (App) getApplication();

setContentView(R.layout.inbox);

11 changes: 10 additions & 1 deletion src/org/envaya/kalsms/IncomingMessage.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,15 @@ public IncomingMessage(App app, String from, String message, long timestampMilli
this.timestampMillis = timestampMillis;
}

public boolean isForwardable()
{
/*
* don't forward messages from shortcodes
* because they're likely to be spam or messages from network
*/
return from.length() > 5;
}

public String getMessageBody()
{
return message;
@@ -54,7 +63,7 @@ public void tryForwardToServer() {


protected Intent getRetryIntent() {
Intent intent = new Intent(app.context, IncomingMessageRetry.class);
Intent intent = new Intent(app, IncomingMessageRetry.class);
intent.setData(Uri.parse("kalsms://incoming/" + this.getId()));
return intent;
}
2 changes: 1 addition & 1 deletion src/org/envaya/kalsms/IncomingMessageRetry.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public class IncomingMessageRetry extends BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent)
{
App app = App.getInstance(context.getApplicationContext());
App app = (App) context.getApplicationContext();
app.retryIncomingMessage(intent.getData().getLastPathSegment());
}
}
22 changes: 22 additions & 0 deletions src/org/envaya/kalsms/MMSReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.envaya.kalsms;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MMSReceiver extends BroadcastReceiver {

private App app;

@Override
public void onReceive(Context context, Intent intent) {
app = (App) context.getApplicationContext();

if (!app.isEnabled())
{
return;
}

app.log("WAP Push received");
}
}
Loading