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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.envaya.kalsms"
android:versionCode="2"
android:versionName="2.0-beta">
android:versionCode="3"
android:versionName="2.0-beta 2">
<uses-sdk android:minSdkVersion="4" />

View File

@ -122,6 +122,8 @@ public final class App extends Application {
outgoingMessagePackages.add(getPackageName());
mmsObserver = new MmsObserver(this);
try
{
packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
@ -152,15 +154,23 @@ public final class App extends Application {
}
}
mmsObserver = new MmsObserver(this);
mmsObserver.register();
enabledChanged();
setOutgoingMessageAlarm();
updateEnabledNotification();
log(Html.fromHtml("<b>Press Menu to edit settings.</b>"));
}
public void updateEnabledNotification()
public void enabledChanged()
{
if (isEnabled())
{
mmsObserver.register();
}
else
{
mmsObserver.unregister();
}
setOutgoingMessageAlarm();
startService(new Intent(this, ForegroundService.class));
}

View File

@ -24,10 +24,29 @@ public abstract class IncomingMessage extends QueuedMessage {
}
/*
* don't forward messages from shortcodes
* because they're likely to be spam or messages from network
* Don't forward messages from shortcodes or users with
* 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()

View File

@ -16,11 +16,6 @@ final class MmsObserver extends ContentObserver {
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(
MmsUtils.OBSERVER_URI, true, this);
@ -33,6 +28,11 @@ final class MmsObserver extends ContentObserver {
}
}
public void unregister()
{
app.getContentResolver().unregisterContentObserver(this);
}
@Override
public void onChange(final boolean selfChange) {
super.onChange(selfChange);

View File

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

View File

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