mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
when nbs send is to my own phone number, just put the packet in the
incoming queue. T-mobile will deliver the message, but it's much faster this way and while I'm still sending too many messages avoids triggering the undismissable "this app is sending too many SMS messages" Android warning alert.
This commit is contained in:
parent
fa856e1db0
commit
01c4fa620e
1 changed files with 37 additions and 48 deletions
|
@ -116,16 +116,20 @@ public class SMSService extends XWService {
|
||||||
public String number;
|
public String number;
|
||||||
public boolean isGSM;
|
public boolean isGSM;
|
||||||
}
|
}
|
||||||
|
private static SMSPhoneInfo s_phoneInfo;
|
||||||
|
|
||||||
public static SMSPhoneInfo getPhoneInfo( Context context )
|
public static SMSPhoneInfo getPhoneInfo( Context context )
|
||||||
{
|
{
|
||||||
TelephonyManager mgr = (TelephonyManager)
|
if ( null == s_phoneInfo ) {
|
||||||
context.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager mgr = (TelephonyManager)
|
||||||
String number = mgr.getLine1Number();
|
context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
String number = mgr.getLine1Number();
|
||||||
|
|
||||||
int type = mgr.getPhoneType();
|
int type = mgr.getPhoneType();
|
||||||
boolean isGSM = TelephonyManager.PHONE_TYPE_GSM == type;
|
boolean isGSM = TelephonyManager.PHONE_TYPE_GSM == type;
|
||||||
return new SMSPhoneInfo( number, isGSM );
|
s_phoneInfo = new SMSPhoneInfo( number, isGSM );
|
||||||
|
}
|
||||||
|
return s_phoneInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void smsToastEnable( boolean newVal )
|
public static void smsToastEnable( boolean newVal )
|
||||||
|
@ -406,30 +410,6 @@ public class SMSService extends XWService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] breakAndEncode( String msg ) throws java.io.IOException
|
|
||||||
{
|
|
||||||
// TODO: as optimization, truncate header when only one packet
|
|
||||||
// required
|
|
||||||
Assert.assertFalse( msg.contains(":") );
|
|
||||||
int count = (msg.length() + (MAX_LEN_TEXT-1)) / MAX_LEN_TEXT;
|
|
||||||
String[] result = new String[count];
|
|
||||||
int msgID = ++s_nSent % 0x000000FF;
|
|
||||||
|
|
||||||
int start = 0;
|
|
||||||
int end = 0;
|
|
||||||
for ( int ii = 0; ii < count; ++ii ) {
|
|
||||||
int len = msg.length() - end;
|
|
||||||
if ( len > MAX_LEN_TEXT ) {
|
|
||||||
len = MAX_LEN_TEXT;
|
|
||||||
}
|
|
||||||
end += len;
|
|
||||||
result[ii] = String.format( "0:%X:%X:%X:%s", msgID, ii, count,
|
|
||||||
msg.substring( start, end ) );
|
|
||||||
start = end;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[][] breakAndEncode( byte msg[] ) throws java.io.IOException
|
private byte[][] breakAndEncode( byte msg[] ) throws java.io.IOException
|
||||||
{
|
{
|
||||||
int count = (msg.length + (MAX_LEN_BINARY-1)) / MAX_LEN_BINARY;
|
int count = (msg.length + (MAX_LEN_BINARY-1)) / MAX_LEN_BINARY;
|
||||||
|
@ -621,32 +601,41 @@ public class SMSService extends XWService {
|
||||||
{
|
{
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
if ( XWPrefs.getSMSEnabled( this ) ) {
|
if ( XWPrefs.getSMSEnabled( this ) ) {
|
||||||
short nbsPort = (short)Integer.parseInt( getString( R.string.nbs_port ) );
|
String myPhone = getPhoneInfo( this ).number;
|
||||||
try {
|
if ( PhoneNumberUtils.compare( phone, myPhone ) ) {
|
||||||
SmsManager mgr = SmsManager.getDefault();
|
|
||||||
PendingIntent sent = makeStatusIntent( MSG_SENT );
|
|
||||||
PendingIntent delivery = makeStatusIntent( MSG_DELIVERED );
|
|
||||||
for ( byte[] fragment : fragments ) {
|
for ( byte[] fragment : fragments ) {
|
||||||
mgr.sendDataMessage( phone, null, nbsPort, fragment, sent,
|
handleFrom( this, fragment, phone );
|
||||||
delivery );
|
|
||||||
DbgUtils.logf( "SMSService.sendBuffers(): sent %d byte fragment",
|
|
||||||
fragment.length );
|
|
||||||
}
|
|
||||||
if ( s_showToasts ) {
|
|
||||||
DbgUtils.showf( this, "sent %dth msg", s_nSent );
|
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} catch ( IllegalArgumentException iae ) {
|
} else {
|
||||||
DbgUtils.logf( "sendBuffers(%s): %s", phone, iae.toString() );
|
short nbsPort = (short)Integer.parseInt( getString( R.string.nbs_port ) );
|
||||||
} catch ( NullPointerException npe ) {
|
try {
|
||||||
Assert.fail(); // shouldn't be trying to do this!!!
|
SmsManager mgr = SmsManager.getDefault();
|
||||||
} catch ( Exception ee ) {
|
PendingIntent sent = makeStatusIntent( MSG_SENT );
|
||||||
DbgUtils.loge( ee );
|
PendingIntent delivery = makeStatusIntent( MSG_DELIVERED );
|
||||||
|
for ( byte[] fragment : fragments ) {
|
||||||
|
mgr.sendDataMessage( phone, null, nbsPort, fragment, sent,
|
||||||
|
delivery );
|
||||||
|
DbgUtils.logf( "SMSService.sendBuffers(): sent %d byte fragment",
|
||||||
|
fragment.length );
|
||||||
|
}
|
||||||
|
success = true;
|
||||||
|
} catch ( IllegalArgumentException iae ) {
|
||||||
|
DbgUtils.logf( "sendBuffers(%s): %s", phone, iae.toString() );
|
||||||
|
} catch ( NullPointerException npe ) {
|
||||||
|
Assert.fail(); // shouldn't be trying to do this!!!
|
||||||
|
} catch ( Exception ee ) {
|
||||||
|
DbgUtils.loge( ee );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DbgUtils.logf( "sendBuffers(): dropping because SMS disabled" );
|
DbgUtils.logf( "sendBuffers(): dropping because SMS disabled" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( s_showToasts && success ) {
|
||||||
|
DbgUtils.showf( this, "sent %dth msg", s_nSent );
|
||||||
|
}
|
||||||
|
|
||||||
ConnStatusHandler.updateStatusOut( this, null,
|
ConnStatusHandler.updateStatusOut( this, null,
|
||||||
CommsConnType.COMMS_CONN_SMS,
|
CommsConnType.COMMS_CONN_SMS,
|
||||||
success );
|
success );
|
||||||
|
|
Loading…
Reference in a new issue