5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-12-04 20:45:32 +00:00

avoid forwarding sms from network; unregister mms observer when kalsms disabled

This commit is contained in:
Jesse Young 2011-09-21 11:53:48 -07:00
parent 687400f91a
commit b6a372d728
6 changed files with 52 additions and 29 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.envaya.kalsms" package="org.envaya.kalsms"
android:versionCode="2" android:versionCode="3"
android:versionName="2.0-beta"> android:versionName="2.0-beta 2">
<uses-sdk android:minSdkVersion="4" /> <uses-sdk android:minSdkVersion="4" />

View File

@ -122,6 +122,8 @@ public final class App extends Application {
outgoingMessagePackages.add(getPackageName()); outgoingMessagePackages.add(getPackageName());
mmsObserver = new MmsObserver(this);
try try
{ {
packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
@ -140,7 +142,7 @@ public final class App extends Application {
log("Server URL is: " + getDisplayString(getServerUrl())); log("Server URL is: " + getDisplayString(getServerUrl()));
log("Your phone number is: " + getDisplayString(getPhoneNumber())); log("Your phone number is: " + getDisplayString(getPhoneNumber()));
if (isTestMode()) if (isTestMode())
{ {
log("Test mode is ON"); log("Test mode is ON");
@ -150,19 +152,27 @@ public final class App extends Application {
{ {
log(" " + sender); log(" " + sender);
} }
} }
enabledChanged();
mmsObserver = new MmsObserver(this); log(Html.fromHtml("<b>Press Menu to edit settings.</b>"));
mmsObserver.register();
setOutgoingMessageAlarm();
updateEnabledNotification();
} }
public void updateEnabledNotification() public void enabledChanged()
{ {
if (isEnabled())
{
mmsObserver.register();
}
else
{
mmsObserver.unregister();
}
setOutgoingMessageAlarm();
startService(new Intent(this, ForegroundService.class)); startService(new Intent(this, ForegroundService.class));
} }
public PackageInfo getPackageInfo() public PackageInfo getPackageInfo()
{ {

View File

@ -24,10 +24,29 @@ public abstract class IncomingMessage extends QueuedMessage {
} }
/* /*
* don't forward messages from shortcodes * Don't forward messages from shortcodes or users with
* because they're likely to be spam or messages from network * addresses like 'Vodacom' because they're likely to be
*/ * messages from network, or spam. At least for network
return from.length() > 5; * messages we should let them go in to the Messaging inbox
* because the person managing this phone needs to know
* when they're out of credit, etc.
*
* The minimum length of normal subscriber numbers doesn't
* seem to be specified, but in practice seems to be
* at least 7 digits everywhere.
*/
int fromDigits = 0;
int fromLength = from.length();
for (int i = 0; i < fromLength; i++)
{
if (Character.isDigit(from.charAt(i)))
{
fromDigits++;
}
}
return fromDigits >= 7;
} }
public String getFrom() public String getFrom()

View File

@ -16,11 +16,6 @@ final class MmsObserver extends ContentObserver {
public void register() public void register()
{ {
/*
* Content observers can watch the MMS inbox URI for changes;
* This is the URL passed to PduPersister.persist by
* com.android.mms.transaction.RetrieveTransaction.run
*/
app.getContentResolver().registerContentObserver( app.getContentResolver().registerContentObserver(
MmsUtils.OBSERVER_URI, true, this); MmsUtils.OBSERVER_URI, true, this);
@ -32,6 +27,11 @@ final class MmsObserver extends ContentObserver {
mmsUtils.markOldMms(mms); mmsUtils.markOldMms(mms);
} }
} }
public void unregister()
{
app.getContentResolver().unregisterContentObserver(this);
}
@Override @Override
public void onChange(final boolean selfChange) { public void onChange(final boolean selfChange) {

View File

@ -79,12 +79,7 @@ public class Main extends Activity {
IntentFilter logReceiverFilter = new IntentFilter(); IntentFilter logReceiverFilter = new IntentFilter();
logReceiverFilter.addAction(App.LOG_INTENT); logReceiverFilter.addAction(App.LOG_INTENT);
registerReceiver(logReceiver, logReceiverFilter); registerReceiver(logReceiver, logReceiverFilter);
if (savedInstanceState == null)
{
app.log(Html.fromHtml("<b>Press Menu to edit settings.</b>"));
}
} }
@Override @Override

View File

@ -101,8 +101,7 @@ public class Prefs extends PreferenceActivity implements OnSharedPreferenceChang
else if (key.equals("enabled")) else if (key.equals("enabled"))
{ {
app.log(app.isEnabled() ? "SMS Gateway started." : "SMS Gateway stopped."); app.log(app.isEnabled() ? "SMS Gateway started." : "SMS Gateway stopped.");
app.setOutgoingMessageAlarm(); app.enabledChanged();
app.updateEnabledNotification();
} }
updatePrefSummary(findPreference(key)); updatePrefSummary(findPreference(key));