dexapier / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

smsGetMessageById (python) does not include last received sms message ID #620

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What device(s) are you experiencing the problem on?

Samsung Galaxy SII

What firmware version are you running on the device?

Android Version 2.3.6
Kernel Version 2.6.35.11

What steps will reproduce the problem?
1. register broadcast
  ACTION="android.provider.Telephony.SMS_RECEIVED"
  a = android.Android()
  print a.eventRegisterForBroadcast(ACTION, False)

  p=a.startEventDispatcher()
  s=socket.socket()
  s.connect(("localhost", p.result))
  f=s.makefile()

2. send an sms message with body "AAAA" to Android
3. send an sms message with body "BBBB" to Android
4. the two messages are received by us and our script processed the the 
SMS_RECEIVED action just fine.  then we call smsGetMessageIds(True)

  messages = a.smsGetMessageIds(True)

What is the expected output? What do you see instead?

the messages list should contain the message IDs for both the "AAAA" and "BBBB" 
messages but only contains the ID for the "AAAA" message.

What version of the product are you using? On what operating system?

I am currently using sl4a-r5 on Android Gingerbread.

Please provide any additional information below.

Original issue reported on code.google.com by etol...@gmail.com on 11 Apr 2012 at 1:55

GoogleCodeExporter commented 9 years ago
What happens if you send three messages? Do you get one or two?

Original comment by zele...@gmail.com on 12 Apr 2012 at 10:03

GoogleCodeExporter commented 9 years ago
The last one is always missing.  So if I send 3 messages then 
smsGetMessageIds() will not return the last one - only the two before it.

send "AAAA"
send "BBBB"
send "CCCC"

smsGetMessageIds will only return the id for "AAAA" and "BBBB".

Original comment by etol...@gmail.com on 13 Apr 2012 at 3:41

GoogleCodeExporter commented 9 years ago
I think I know what's going on. I'll work on a patch for this over the weekend.

Original comment by zele...@gmail.com on 13 Apr 2012 at 7:18

GoogleCodeExporter commented 9 years ago
Try this one. 

Original comment by zele...@gmail.com on 13 Apr 2012 at 11:08

Attachments:

GoogleCodeExporter commented 9 years ago
Looking at the patch and the original code, I'm surprised the original code 
doesn't work. The cursor returned from the contentresolver query is supposed to 
be positioned *before* the first record, so that while(cursor.moveNext()) 
should just work.

Is this a workaround for an android bug?

Original comment by rjmatthews62 on 14 Apr 2012 at 12:19

GoogleCodeExporter commented 9 years ago
Also, does smsGetMessages return the right number?

Original comment by rjmatthews62 on 14 Apr 2012 at 12:21

GoogleCodeExporter commented 9 years ago
This one is a little more elegant fix. In addition this fixes smsGetMessages 
that has a similar bug.

Original comment by zele...@gmail.com on 14 Apr 2012 at 1:29

Attachments:

GoogleCodeExporter commented 9 years ago
Robbie, while(cursor.moveNext()) moves beyond the first row before 
cursor.getInt(0) gets a chance to read the row. It is my understanding that 
sqlite reads the row after the cursor, and not before.

Original comment by zele...@gmail.com on 14 Apr 2012 at 1:31

GoogleCodeExporter commented 9 years ago
OK: getSMSMessageIds etc work fine as is.
The problem is one of timing: the SMSReceived message occurs BEFORE message is 
inserted into the Inbox. Thus you are getting a race condition.
A short delay before querying message ids should solve the problem.

Original comment by rjmatthews62 on 14 Apr 2012 at 1:34

GoogleCodeExporter commented 9 years ago
You are right. Just tested vanilla r5 and I do get all the messages. I am 
testing without intent listener, so it may be race indeed.

Original comment by zele...@gmail.com on 14 Apr 2012 at 2:58

GoogleCodeExporter commented 9 years ago
Solution found (comment 9) ... issue is because of a race condition.

Original comment by rjmatthews62 on 14 Apr 2012 at 3:38

GoogleCodeExporter commented 9 years ago
Great!  Which apk should I use?  Or do I wait for the next release?

Original comment by etol...@gmail.com on 17 Apr 2012 at 1:34