Streams & Android V4 - V5

Monkey Targets Forums/Android/Streams & Android V4 - V5

Yeshu777(Posted 2015) [#1]
Hi,

As you may of noticed, currently having some problems with Android V5, which I'd be grateful for some feedback on.

The following 'test bed' code works fine on V4 devices (which will connect to Server and log in) - but not V5, which connects and crashes as soon as the stream is accessed.

Error output is as follows:

E/AndroidRuntime(26704): java.lang.UnsupportedOperationException

E/AndroidRuntime(26704): 	at java.nio.DirectByteBuffer.protectedArray(DirectByteBuffer.java:289)

E/AndroidRuntime(26704): 	at java.nio.ByteBuffer.array(ByteBuffer.java:139)

E/AndroidRuntime(26704): 	at com.lsd.sitemanager.BBSocket.Receive(MonkeyGame.java:1958)



Any advice / suggestions, most appreciated.

Yeshu777




ImmutableOctet(SKNG)(Posted 2015) [#2]
From the look of it, you're sending and receiving with the same buffer. That's not valid when using asynchronous methods. You're basically causing a race-condition. Use one (Or more) buffer(s) for receiving, and one for sending. Common practice is to use a fixed size for buffers, and use a pool to manage their allocation. Also keep in mind that sending unrelated data can cause problems. It's best to keep track of the lengths of the segments you write in your buffers, and send with that. I said this before, but you should probably use 'brl.datastream', or a custom 'Stream' setup, like my 'publicdatastream' module, as used here.

EDIT: This may or may not be the issue, but is still possible. (First use of 'ReceiveAsync') - Try removing your call to 'ReceiveAsync' at the beginning.


Yeshu777(Posted 2015) [#3]
Hi Anthony,

Many thanks for the feedback, albeit that's not where the problem lies.

>EDIT: This may or may not be the issue, but is still possible. (First use of 'ReceiveAsync') - Try removing your call to 'ReceiveAsync' at the beginning.

I modified the above code using tx_buffer & rx_buffers - and placed the 'ReceiveAsync' in 'On Connect Complete' Method in the following code.

All tested & working fine on Android V4 devices...



The problem / crash still only appears on Android V5 as soon as the stream is accessed (and it's own 'low-level' buffer). So annoying.

Error Output:


E/AndroidRuntime(28377): java.lang.UnsupportedOperationException

E/AndroidRuntime(28377): 	at java.nio.DirectByteBuffer.protectedArray(DirectByteBuffer.java:289)

E/AndroidRuntime(28377): 	at java.nio.ByteBuffer.array(ByteBuffer.java:139)

E/AndroidRuntime(28377): 	at com.lucid.ftptest.BBSocket.Receive(MonkeyGame.java:1824)

E/AndroidRuntime(28377): 	at com.lucid.ftptest.c_AsyncReceiveOp.p_Execute__UNSAFE__(MonkeyGame.java:4914)



Does the _UNSAFE_ suffix have a meaningful relevance?

Is anyone aware of underlying differences in both the 'stream' & 'socket' operations / implementation on Android V5 ?

Yeshu777