5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-11-09 10:20:25 +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);
@ -152,15 +154,23 @@ public final class App extends Application {
} }
} }
mmsObserver = new MmsObserver(this); enabledChanged();
mmsObserver.register();
setOutgoingMessageAlarm(); log(Html.fromHtml("<b>Press Menu to edit settings.</b>"));
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));
} }

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
* 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.
*/ */
return from.length() > 5; 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);
@ -33,6 +28,11 @@ final class MmsObserver extends ContentObserver {
} }
} }
public void unregister()
{
app.getContentResolver().unregisterContentObserver(this);
}
@Override @Override
public void onChange(final boolean selfChange) { public void onChange(final boolean selfChange) {
super.onChange(selfChange); super.onChange(selfChange);

View File

@ -80,11 +80,6 @@ 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));