Make it less likely that a message received while I'm not intercepting

them will be opened more than once: track whether I've searched the
SMS db, and only clear that setting when SMS play is *disabled*.
This commit is contained in:
Eric House 2012-10-29 21:20:32 -07:00
parent ba0f91c438
commit 80a79b6991
5 changed files with 44 additions and 22 deletions

View file

@ -68,6 +68,7 @@
<string name="key_sms_phones">key_sms_phones</string>
<string name="key_connstat_data">key_connstat_data</string>
<string name="key_dev_id">key_dev_id</string>
<string name="key_checked_sms">key_checked_sms</string>
<string name="key_notagain_sync">key_notagain_sync</string>
<string name="key_notagain_chat">key_notagain_chat</string>

View file

@ -2141,4 +2141,5 @@
<string name="default_loc">Store wordlists internally</string>
<string name="default_loc_summary">(Not in external/sdcard memory)</string>
<string name="sms_searching_toast">Searching SMS messages...</string>
</resources>

View file

@ -39,6 +39,7 @@ public class PrefsActivity extends PreferenceActivity
private String m_keyLogging;
private String m_smsToasting;
private String m_smsEnable;
@Override
protected Dialog onCreateDialog( int id )
@ -118,6 +119,7 @@ public class PrefsActivity extends PreferenceActivity
m_keyLogging = getString( R.string.key_logging_on );
m_smsToasting = getString( R.string.key_show_sms );
m_smsEnable = getString( R.string.key_enable_sms );
Button button = (Button)findViewById( R.id.revert_colors );
button.setOnClickListener( new View.OnClickListener() {
@ -156,6 +158,12 @@ public class PrefsActivity extends PreferenceActivity
DbgUtils.logEnable( sp.getBoolean( key, false ) );
} else if ( key.equals( m_smsToasting ) ) {
SMSService.smsToastEnable( sp.getBoolean( key, false ) );
} else if ( key.equals( m_smsEnable ) ) {
if ( sp.getBoolean( key, true ) ) {
SMSService.checkForInvites( this );
} else {
XWPrefs.setHaveCheckedSMS( this, false );
}
}
}

View file

@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@ -76,7 +77,6 @@ public class SMSService extends Service {
private static Boolean s_showToasts = null;
private static MultiService s_srcMgr = null;
private static boolean s_dbCheckPending = true;
// All messages are base64-encoded byte arrays. The first byte is
// always one of these. What follows depends.
@ -101,7 +101,8 @@ public class SMSService extends Service {
}
}
public static void handleFrom( Context context, String buffer, String phone )
public static void handleFrom( Context context, String buffer,
String phone )
{
Intent intent = getIntentTo( context, HANDLE );
intent.putExtra( BUFFER, buffer );
@ -230,15 +231,14 @@ public class SMSService extends Service {
int cmd = intent.getIntExtra( CMD_STR, -1 );
switch( cmd ) {
case CHECK_MSGDB:
if ( s_dbCheckPending ) {
if ( Utils.firstBootEver( this ) ) {
new Thread( new Runnable() {
if ( ! XWPrefs.getHaveCheckedSMS( this ) ) {
Utils.showToast( this, R.string.sms_searching_toast );
XWPrefs.setHaveCheckedSMS( this, true );
new Thread( new Runnable() {
public void run() {
checkMsgDB();
}
} ).start();
}
s_dbCheckPending = false;
}
break;
case HANDLE:
@ -288,7 +288,7 @@ public class SMSService extends Service {
result = Service.START_STICKY_COMPATIBILITY;
}
return result;
}
} // onStartCommand
@Override
public IBinder onBind( Intent intent )
@ -632,25 +632,27 @@ public class SMSService extends Service {
private void checkMsgDB()
{
Uri uri = Uri.parse( "content://sms/inbox" );
ContentResolver resolver = getContentResolver();
String[] columns = new String[] { "body","address" };
Cursor cursor = getContentResolver().query( uri, columns,
null, null, null );
try {
int bodyIndex = cursor.getColumnIndexOrThrow( "body" );
int phoneIndex = cursor.getColumnIndexOrThrow( "address" );
while ( cursor.moveToNext() ) {
String msg = fromPublicFmt( cursor.getString( bodyIndex ) );
if ( null != msg ) {
String number = cursor.getString( phoneIndex );
if ( null != number ) {
handleFrom( this, msg, number );
Cursor cursor = resolver.query( uri, columns, null, null, null );
if ( 0 < cursor.getCount() ) {
try {
int bodyIndex = cursor.getColumnIndexOrThrow( "body" );
int phoneIndex = cursor.getColumnIndexOrThrow( "address" );
while ( cursor.moveToNext() ) {
String msg = fromPublicFmt( cursor.getString( bodyIndex ) );
if ( null != msg ) {
String number = cursor.getString( phoneIndex );
if ( null != number ) {
handleFrom( this, msg, number );
}
}
}
} catch ( Exception ee ) {
DbgUtils.loge( ee );
}
cursor.close();
} catch ( Exception ee ) {
DbgUtils.loge( ee );
}
cursor.close();
}
private void sendResult( MultiEvent event, Object ... args )

View file

@ -189,6 +189,16 @@ public class XWPrefs {
return getPrefsBoolean( context, R.string.key_default_loc, true );
}
public static boolean getHaveCheckedSMS( Context context )
{
return getPrefsBoolean( context, R.string.key_checked_sms, false );
}
public static void setHaveCheckedSMS( Context context, boolean newValue )
{
setPrefsBoolean( context, R.string.key_checked_sms, newValue );
}
public static DictUtils.DictLoc getDefaultLoc( Context context )
{
boolean internal = getDefaultLocInternal( context );