title: What Android Code writes an Incoming SMS Message to the SMS Database?
body: <p>SMS messages are encoded in a PDU format (<a href="http://www.dreamfabric.com/sms/" rel="nofollow">http://www.dreamfabric.com/sms/</a>) when they are sent and end up in a database in Android ("content://sms").  I am trying to find out what the data flow is when an SMS message is received.  In particular I would like to know what piece of code decodes the PDU and makes the entry into the SMS database.</p>
  
  <p>The reason I am interested is that in some cases the timestamp in the database is different than the time the message was sent.  For me in some locations it is 5 hours in the future.  It depends on the tower, and I have been told it is because it gets the wrong time from the tower.  However, the time stamp, including the time zone, should be encoded in the PDU and the time on the phone, which also comes from the tower, is correct.  Thus, it doesn't make sense to me.  I am trying to trace it down.</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>androidnoob,</p>
  
  <p>Thanks for the information.  I can get all the messages in "content://sms" or "content://sms/inbox" or "content://sms/sent" or some others.  I think that is what the links you suggest are about.  These messages are in databases and have already been put there by the code I think I am after.</p>
  
  <p>I can also set a BroadcastReceiver for "android.provider.Telephony.SMS_RECEIVED".  The messages I get in the callback are not yet in the database.  The PDUs are available, but I don't know if they are the same ones that got sent or if they are generated.</p>
  
  <p>The classes that supply this information are in com.android.internal.telephony.  These classes are not in android.jar, and I do not have the source code to trace into them.  It appears they may be obtained from git://android.get.kernel.org/platform/base/telephony.  The problem is (1) I am not very experienced with Git and (2) this repository appears to be down owing to its being hacked around Sept. 1.  In any event I haven't been able to get them, owing either to its being down or my inexperience.</p>
  
  <p>I have not been able to test what happens when I am in the location that gives the bad time stamp, but I have noticed that if I send a message to myself where I am now, the incoming time stamp is about 30 sec before the time I actually sent the message, according to the device time.  At the time of the callback the message I sent is in the database, and some time later the received message is also in the database, with its incoming time stamp (date column) and a higher _id, usually the originating _id + 1.  This means it has a higher _id but an earlier time. This makes it look like the message was received slightly before it was sent.  In the bad location the time stamp is 5 hours in the future instead of 30 sec in the past.  In neither case does it appear to be the time on the device when it was sent.</p>