diff --git a/xwords4/android/XWords4-bt/AndroidManifest.xml b/xwords4/android/XWords4-bt/AndroidManifest.xml index d81c75bd0..13800c86d 100644 --- a/xwords4/android/XWords4-bt/AndroidManifest.xml +++ b/xwords4/android/XWords4-bt/AndroidManifest.xml @@ -37,7 +37,7 @@ - + GetArrayLength( env, jbytes ); + jbyte* elems = (*env)->GetByteArrayElements( env, jbytes, NULL ); + XP_ASSERT( !!elems ); + + XP_UCHAR out[4+(inlen*4/3)]; + XP_U16 outlen = VSIZE( out ); + binToSms( out, &outlen, (const XP_U8*)elems, inlen ); + + (*env)->ReleaseByteArrayElements( env, jbytes, elems, 0 ); + + jstring result = (*env)->NewStringUTF( env, out ); + return result; +} + +JNIEXPORT jbyteArray JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_base64Decode +( JNIEnv* env, jclass C, jstring jstr ) +{ + jbyteArray result = NULL; + const char* instr = (*env)->GetStringUTFChars( env, jstr, NULL ); + XP_U16 inlen = (*env)->GetStringUTFLength( env, jstr ); + XP_U8 out[inlen]; + XP_U16 outlen = VSIZE(out); + if ( smsToBin( out, &outlen, instr, inlen ) ) { + result = (*env)->NewByteArray( env, outlen ); + jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL ); + XP_MEMCPY( jelems, out, outlen ); + (*env)->ReleaseByteArrayElements( env, result, jelems, 0 ); + } else { + XP_ASSERT(0); + } + (*env)->ReleaseStringUTFChars( env, jstr, instr ); + return result; +} +#endif + #endif /* XWFEATURE_BOARDWORDS */ diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java index 4e89b74b8..514911b7a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java @@ -28,7 +28,6 @@ import android.os.Bundle; import android.os.IBinder; import android.telephony.SmsManager; import android.telephony.SmsMessage; -import android.util.Base64; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -40,6 +39,7 @@ import java.lang.System; import junit.framework.Assert; import org.eehouse.android.xw4.jni.CommsAddrRec; +import org.eehouse.android.xw4.jni.XwJNI; public class SMSService extends Service { @@ -233,7 +233,7 @@ public class SMSService extends Service { das.write( bytes, 0, bytes.length ); das.flush(); - String as64 = Base64.encodeToString( bas.toByteArray(), Base64.NO_WRAP ); + String as64 = XwJNI.base64Encode( bas.toByteArray() ); String[] msgs = breakAndEncode( as64 ); return sendBuffers( msgs, phone ); } @@ -325,7 +325,7 @@ public class SMSService extends Service { int count, String msg ) { if ( index == 0 && count == 1 ) { - disAssemble( senderPhone, msg.getBytes() ); + disAssemble( senderPhone, msg ); } else { synchronized( s_partialMsgs ) { HashMap perPhone = @@ -343,7 +343,7 @@ public class SMSService extends Service { if ( store.isComplete() ) { s_partialMsgs.remove( id ); - byte[] fullMsg = store.message(); + String fullMsg = store.message(); perPhone.remove( id ); disAssemble( senderPhone, fullMsg ); } @@ -351,10 +351,10 @@ public class SMSService extends Service { } } - private void disAssemble( String senderPhone, byte[] fullMsg ) + private void disAssemble( String senderPhone, String fullMsg ) { DbgUtils.logf( "disAssemble()" ); - byte[] data = Base64.decode( fullMsg, Base64.NO_WRAP ); + byte[] data = XwJNI.base64Decode( fullMsg ); DataInputStream dis = new DataInputStream( new ByteArrayInputStream(data) ); try { @@ -487,16 +487,13 @@ public class SMSService extends Service { return complete; } - public byte[] message() + public String message() { - byte[] result = new byte[m_fullLength]; - int offset = 0; - for ( int ii = 0; ii < m_msgs.length; ++ii ) { - byte[] src = m_msgs[ii].getBytes(); - System.arraycopy( src, 0, result, offset, src.length ); - offset += src.length; + StringBuffer sb = new StringBuffer(m_fullLength); + for ( String msg : m_msgs ) { + sb.append( msg ); } - return result; + return sb.toString(); } } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java index 722bd5de4..d8f5c9a6b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java @@ -255,4 +255,8 @@ public class XwJNI { public static native int[] dict_iter_getIndices( int closure ); public static native int dict_iter_getStartsWith( int closure, String prefix ); + + // base64 stuff since 2.1 doesn't support it in java + public static native String base64Encode( byte[] in ); + public static native byte[] base64Decode( String in ); }