5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2024-11-08 18:00:27 +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);
@ -140,7 +142,7 @@ 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");
@ -150,19 +152,27 @@ public final class App extends Application {
{
log(" " + sender);
}
}
}
enabledChanged();
mmsObserver = new MmsObserver(this);
mmsObserver.register();
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));
}
}
public PackageInfo getPackageInfo()
{

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

View File

@ -79,12 +79,7 @@ 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>"));
}
registerReceiver(logReceiver, logReceiverFilter);
}
@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));