mirror of
https://github.com/cwinfo/envayasms.git
synced 2024-12-04 20:45:32 +00:00
add test mode to allow testing KalSMS on a phone that is also being used for normal messaging; allow user to configure specific phone numbers to handle
This commit is contained in:
parent
3357de7e4e
commit
eb808372f8
@ -25,14 +25,16 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ui.Help" android:label="@string/app_name">
|
||||
<activity android:name=".ui.Help" android:label="KalSMS : Help">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ui.ForwardInbox" android:label="@string/app_name">
|
||||
<activity android:name=".ui.TestPhoneNumbers" android:label="KalSMS : Test Phone Numbers">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ui.Prefs"
|
||||
android:label="@string/app_name">
|
||||
<activity android:name=".ui.ForwardInbox" android:label="KalSMS : Forward Inbox">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ui.Prefs" android:label="KalSMS : Settings">
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".receiver.SmsReceiver">
|
||||
|
7
res/layout/add_test_phone_number.xml
Executable file
7
res/layout/add_test_phone_number.xml
Executable file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/add_test_sender_text"
|
||||
android:layout_width="fill_parent"
|
||||
android:inputType="phone"
|
||||
android:layout_height="wrap_content">
|
||||
</EditText>
|
9
res/layout/test_phone_number.xml
Executable file
9
res/layout/test_phone_number.xml
Executable file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="10dp"
|
||||
android:textColor="#ffffff"
|
||||
android:textStyle="bold"
|
||||
android:textSize="16sp" >
|
||||
</TextView>
|
28
res/layout/test_phone_numbers.xml
Executable file
28
res/layout/test_phone_numbers.xml
Executable file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" android:background="#333333">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10sp"
|
||||
android:text="@string/test_senders">
|
||||
</TextView>
|
||||
|
||||
<ListView android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/add_test_phone_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:onClick="addTestSender"
|
||||
android:text="Add Test Sender" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -1,10 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">KalSMS 2</string>
|
||||
<string name="app_name">KalSMS</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="test">Test Connection</string>
|
||||
<string name="check_now">Check Messages</string>
|
||||
<string name="help">Help</string>
|
||||
<string name="retry_now">Retry</string>
|
||||
<string name="forward_inbox">Fwd Inbox...</string>
|
||||
<string name='test_senders'>When running KalSMS in Test Mode,
|
||||
KalSMS will only forward SMS messages from the phone numbers
|
||||
listed below. (Incoming SMS messages from other phone numbers will be saved
|
||||
in the normal Messaging inbox, and outgoing messages will be ignored.)</string>
|
||||
</resources>
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="enabled"
|
||||
android:title="Enable KalSMS?"
|
||||
android:title="Enable KalSMS"
|
||||
android:defaultValue='false'
|
||||
android:summaryOn="All new SMS will be forwarded between phone and server"
|
||||
android:summaryOff="New SMS will not be forwarded between phone and server"
|
||||
@ -13,12 +13,14 @@
|
||||
<EditTextPreference
|
||||
android:key="server_url"
|
||||
android:title="Server URL"
|
||||
android:inputType="textUri"
|
||||
android:defaultValue=""
|
||||
></EditTextPreference>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="phone_number"
|
||||
android:title="Your phone number"
|
||||
android:inputType="phone"
|
||||
android:defaultValue=""
|
||||
></EditTextPreference>
|
||||
|
||||
@ -38,7 +40,7 @@
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="keep_in_inbox"
|
||||
android:title="Keep new messages?"
|
||||
android:title="Keep new messages"
|
||||
android:summaryOff="Incoming SMS will not be stored in Messaging inbox"
|
||||
android:summaryOn="Incoming SMS will be stored in Messaging inbox"
|
||||
></CheckBoxPreference>
|
||||
@ -52,4 +54,23 @@
|
||||
>
|
||||
</ListPreference>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="test_mode"
|
||||
android:title="Test mode"
|
||||
android:summaryOff="Test mode is off (KalSMS forwards all SMS)"
|
||||
android:summaryOn="Test mode is on (KalSMS only forwards SMS to/from specific phones)"
|
||||
></CheckBoxPreference>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="test_numbers"
|
||||
android:title="Sender phones"
|
||||
android:dependency="test_mode"
|
||||
android:summary="Configure the phone numbers that KalSMS will handle"
|
||||
>
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="org.envaya.kalsms"
|
||||
android:targetClass="org.envaya.kalsms.ui.TestPhoneNumbers" />
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceScreen>
|
@ -18,6 +18,7 @@ import android.text.SpannableStringBuilder;
|
||||
import android.util.Log;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -26,6 +27,8 @@ import org.apache.http.message.BasicNameValuePair;
|
||||
import org.envaya.kalsms.receiver.OutgoingMessagePoller;
|
||||
import org.envaya.kalsms.task.HttpTask;
|
||||
import org.envaya.kalsms.task.PollerTask;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
public final class App extends Application {
|
||||
|
||||
@ -107,6 +110,17 @@ public final class App extends Application {
|
||||
log("Server URL is: " + getDisplayString(getServerUrl()));
|
||||
log("Your phone number is: " + getDisplayString(getPhoneNumber()));
|
||||
|
||||
if (isTestMode())
|
||||
{
|
||||
log("Test mode is ON");
|
||||
log("Test phone numbers:");
|
||||
|
||||
for (String sender : getTestPhoneNumbers())
|
||||
{
|
||||
log(" " + sender);
|
||||
}
|
||||
}
|
||||
|
||||
mmsObserver = new MmsObserver(this);
|
||||
mmsObserver.register();
|
||||
|
||||
@ -270,6 +284,11 @@ public final class App extends Application {
|
||||
return settings.getBoolean("enabled", false);
|
||||
}
|
||||
|
||||
public boolean isTestMode()
|
||||
{
|
||||
return settings.getBoolean("test_mode", false);
|
||||
}
|
||||
|
||||
public boolean getKeepInInbox()
|
||||
{
|
||||
return settings.getBoolean("keep_in_inbox", false);
|
||||
@ -392,6 +411,16 @@ public final class App extends Application {
|
||||
}
|
||||
|
||||
public synchronized void sendOutgoingMessage(OutgoingMessage sms) {
|
||||
|
||||
if (isTestMode() && !isTestPhoneNumber(sms.getTo()))
|
||||
{
|
||||
// this is mostly to prevent accidentally sending real messages to
|
||||
// random people while testing...
|
||||
|
||||
log("Ignoring outgoing SMS to " + sms.getTo());
|
||||
return;
|
||||
}
|
||||
|
||||
Uri uri = sms.getUri();
|
||||
if (outgoingMessages.containsKey(uri)) {
|
||||
log("Duplicate outgoing " + sms.getLogName() + ", skipping");
|
||||
@ -506,4 +535,69 @@ public final class App extends Application {
|
||||
{
|
||||
return mmsUtils;
|
||||
}
|
||||
|
||||
private List<String> testPhoneNumbers;
|
||||
|
||||
public List<String> getTestPhoneNumbers()
|
||||
{
|
||||
if (testPhoneNumbers == null)
|
||||
{
|
||||
testPhoneNumbers = new ArrayList<String>();
|
||||
String phoneNumbersJson = settings.getString("test_phone_numbers", "");
|
||||
|
||||
if (phoneNumbersJson.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
JSONArray arr = new JSONArray(phoneNumbersJson);
|
||||
int numSenders = arr.length();
|
||||
for (int i = 0; i < numSenders; i++)
|
||||
{
|
||||
testPhoneNumbers.add(arr.getString(i));
|
||||
}
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
logError("Error parsing test phone numbers", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return testPhoneNumbers;
|
||||
}
|
||||
|
||||
public void addTestPhoneNumber(String phoneNumber)
|
||||
{
|
||||
List<String> phoneNumbers = getTestPhoneNumbers();
|
||||
log("Added test phone number: " + phoneNumber);
|
||||
phoneNumbers.add(phoneNumber);
|
||||
saveTestPhoneNumbers(phoneNumbers);
|
||||
}
|
||||
|
||||
public void removeTestPhoneNumber(String phoneNumber)
|
||||
{
|
||||
List<String> phoneNumbers = getTestPhoneNumbers();
|
||||
phoneNumbers.remove(phoneNumber);
|
||||
log("Removed test phone number: " + phoneNumber);
|
||||
saveTestPhoneNumbers(phoneNumbers);
|
||||
}
|
||||
|
||||
private void saveTestPhoneNumbers(List<String> phoneNumbers)
|
||||
{
|
||||
settings.edit().putString("test_phone_numbers",
|
||||
new JSONArray(phoneNumbers).toString()
|
||||
).commit();
|
||||
}
|
||||
|
||||
public boolean isTestPhoneNumber(String phoneNumber)
|
||||
{
|
||||
for (String testNumber : getTestPhoneNumbers())
|
||||
{
|
||||
// handle inexactness due to various different ways of formatting numbers
|
||||
if (testNumber.contains(phoneNumber) || phoneNumber.contains(testNumber))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,11 @@ public abstract class IncomingMessage extends QueuedMessage {
|
||||
|
||||
public boolean isForwardable()
|
||||
{
|
||||
if (app.isTestMode() && !app.isTestPhoneNumber(from))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* don't forward messages from shortcodes
|
||||
* because they're likely to be spam or messages from network
|
||||
|
@ -1,9 +1,6 @@
|
||||
|
||||
package org.envaya.kalsms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import org.envaya.kalsms.receiver.OutgoingMessageRetry;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
@ -27,10 +27,6 @@ public class SmsReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
try {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (action.equals("android.provider.Telephony.SMS_RECEIVED")) {
|
||||
|
||||
boolean hasUnhandledMessage = false;
|
||||
|
||||
for (IncomingMessage sms : getMessagesFromIntent(intent)) {
|
||||
@ -41,6 +37,7 @@ public class SmsReceiver extends BroadcastReceiver {
|
||||
}
|
||||
else
|
||||
{
|
||||
app.log("Ignoring incoming SMS from " + sms.getFrom());
|
||||
hasUnhandledMessage = true;
|
||||
}
|
||||
}
|
||||
@ -49,9 +46,8 @@ public class SmsReceiver extends BroadcastReceiver {
|
||||
{
|
||||
this.abortBroadcast();
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
app.logError("Unexpected error in IncomingMessageForwarder", ex, true);
|
||||
app.logError("Unexpected error in SmsReceiver", ex, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class Help extends Activity {
|
||||
String html = "<b>KalSMS</b> is a SMS gateway.<br /><br /> "
|
||||
+ "It forwards all incoming SMS messages received by this phone to a server on the internet, "
|
||||
+ "and also sends outgoing SMS messages from that server to other phones.<br /><br />"
|
||||
+ "(See https://kalsms.net for information about setting up a server.)<br /><br />"
|
||||
+ "(See https://kalsms.net for more information.)<br /><br />"
|
||||
+ "The Settings screen allows you configure KalSMS to work with a particular server, "
|
||||
+ "by entering the server URL, your phone number, "
|
||||
+ "and the password assigned to your phone on the server.<br /><br />"
|
||||
|
@ -90,6 +90,10 @@ public class Prefs extends PreferenceActivity implements OnSharedPreferenceChang
|
||||
{
|
||||
app.log("Phone number changed to: " + app.getDisplayString(app.getPhoneNumber()));
|
||||
}
|
||||
else if (key.equals("test_mode"))
|
||||
{
|
||||
app.log("Test mode changed to: " + (app.isTestMode() ? "ON": "OFF"));
|
||||
}
|
||||
else if (key.equals("password"))
|
||||
{
|
||||
app.log("Password changed");
|
||||
|
107
src/org/envaya/kalsms/ui/TestPhoneNumbers.java
Executable file
107
src/org/envaya/kalsms/ui/TestPhoneNumbers.java
Executable file
@ -0,0 +1,107 @@
|
||||
package org.envaya.kalsms.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import org.envaya.kalsms.App;
|
||||
import org.envaya.kalsms.R;
|
||||
|
||||
public class TestPhoneNumbers extends ListActivity {
|
||||
|
||||
private App app;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.test_phone_numbers);
|
||||
|
||||
app = (App)getApplication();
|
||||
|
||||
ListView lv = getListView();
|
||||
lv.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id)
|
||||
{
|
||||
final String phoneNumber = ((TextView) view).getText().toString();
|
||||
|
||||
new AlertDialog.Builder(TestPhoneNumbers.this)
|
||||
.setTitle("Remove Test Phone")
|
||||
.setMessage("Do you want to remove "+phoneNumber
|
||||
+" from the list of test phone numbers?")
|
||||
.setPositiveButton("OK",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
app.removeTestPhoneNumber(phoneNumber);
|
||||
updateTestPhoneNumbers();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNegativeButton("Cancel",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
updateTestPhoneNumbers();
|
||||
}
|
||||
|
||||
public void updateTestPhoneNumbers()
|
||||
{
|
||||
String[] senders = app.getTestPhoneNumbers().toArray(new String[]{});
|
||||
|
||||
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
|
||||
R.layout.test_phone_number,
|
||||
senders);
|
||||
|
||||
setListAdapter(arrayAdapter);
|
||||
}
|
||||
|
||||
public void addTestSender(View v)
|
||||
{
|
||||
LayoutInflater factory = LayoutInflater.from(this);
|
||||
final EditText textEntryView =
|
||||
(EditText)factory.inflate(R.layout.add_test_phone_number, null);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Add Test Phone")
|
||||
.setMessage("Enter the phone number that you will be testing with:")
|
||||
.setView(textEntryView)
|
||||
.setPositiveButton("OK",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
app.addTestPhoneNumber(textEntryView.getText().toString());
|
||||
updateTestPhoneNumbers();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNegativeButton("Cancel",
|
||||
new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.show();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user