Browse files

LGEInfineon: Convert NITZ date to UTC before broadcasting

  • Loading branch information...
1 parent beda749 commit b1fffafc73b73f8222e0de07f8e8ab6d88356527 @rmcc rmcc committed Nov 6, 2012
Showing with 81 additions and 0 deletions.
  1. +1 −0 include/device_perms.h
  2. +80 −0 ril/telephony/java/com/android/internal/telephony/LGEInfineon.java
View
1 include/device_perms.h
@@ -53,6 +53,7 @@ struct {
{ "persist.service.", AID_RADIO, 0 },
{ "persist.security.",AID_SYSTEM, 0 },
{ "net.pdp", AID_RADIO, AID_RADIO },
+ { "watchdog.reset_progress", AID_RADIO, AID_RADIO },
{ "media.tegra", AID_MEDIA, 0 },
{ NULL, 0, 0 }
};
View
80 ril/telephony/java/com/android/internal/telephony/LGEInfineon.java
@@ -26,6 +26,11 @@
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
+/* NITZ stuffs */
+import android.os.SystemProperties;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
public class LGEInfineon extends RIL implements CommandsInterface {
public LGEInfineon(Context context, int networkMode, int cdmaSubscription) {
@@ -87,6 +92,7 @@ public void onCallStateChanged(int state, String incomingNumber) {
case 1080: ret = responseVoid(p); break; // RIL_UNSOL_LGE_FACTORY_READY
case RIL_UNSOL_LGE_SIM_STATE_CHANGED:
case RIL_UNSOL_LGE_SIM_STATE_CHANGED_NEW: ret = responseVoid(p); break;
+ case RIL_UNSOL_NITZ_TIME_RECEIVED: ret = responseNitz(p); break;
default:
// Rewind the Parcel
p.setDataPosition(dataPosition);
@@ -131,9 +137,83 @@ public void onCallStateChanged(int state, String incomingNumber) {
mIccStatusChangedRegistrants.notifyRegistrants();
}
break;
+ case RIL_UNSOL_NITZ_TIME_RECEIVED:
+ if (RILJ_LOGD) unsljLogRet(response, ret);
+
+ // has bonus long containing milliseconds since boot that the NITZ
+ // time was received
+ long nitzReceiveTime = p.readLong();
+
+ Object[] result = new Object[2];
+
+ result[0] = ret;
+ result[1] = Long.valueOf(nitzReceiveTime);
+
+ boolean ignoreNitz = SystemProperties.getBoolean(
+ TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
+
+ if (ignoreNitz) {
+ if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
+ } else {
+ if (mNITZTimeRegistrant != null) {
+
+ mNITZTimeRegistrant
+ .notifyRegistrant(new AsyncResult (null, result, null));
+ } else {
+ // in case NITZ time registrant isnt registered yet
+ mLastNITZTimeInfo = result;
+ }
+ }
+ break;
}
}
+ private Object
+ responseNitz(Parcel p) {
+ int tzoffset, dst=0;
+ String parceldata, parcelextra;
+ String response;
+ SimpleDateFormat dateFormatter;
+ SimpleDateFormat dateParser;
+
+ /* Get the actual date string */
+ parceldata = p.readString();
+
+ /* Break 12/11/6,19:0:15+44,1 into...
+ * parcelitem[0] (date), hourbreak[0] (time),
+ * hourbreak[1] (tz offset), parcelitem[2] (dst) */
+
+ String [] parcelitem = parceldata.split(",");
+ String [] hourbreak = parcelitem[1].split("\\+");

doesn't work for GMT-32 and throws exception. (i don't know how to fix it yet.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ parceldata = parcelitem[0] + "," + hourbreak[0]; // assuming there is always one comma at least
+ tzoffset = Integer.parseInt(hourbreak[1]); // TZ diff in quarter-hours
+
+ parcelextra = (parcelitem.length > 2 ? parcelitem[2] : "0");
+ dst = Integer.parseInt(parcelextra);
+
+ /* WTH... Date may come with 4 digits in the year, reduce to 2 */
+ try {
+ dateFormatter = new SimpleDateFormat("yy/MM/dd,HH:mm:ss");
+ dateParser = new SimpleDateFormat("yy/MM/dd,HH:mm:ss");
+
+ /* Directly calculate UTC time using DST Offset */
+ int offset = tzoffset*15*60*1000; // DST corrected
+ long when = dateParser.parse(parceldata).getTime() - offset;
+ Date d = new Date(when);
+ response = dateFormatter.format(d);
+
+ } catch (java.text.ParseException tpe) {
+ riljLog("NITZ TZ conversion failed: " + tpe);
+ response = parceldata;
+ }
+
+ /* Append the timezone */
+ response = response + ((tzoffset < 0) ? "" : "+") + tzoffset;
+ /* Add DST */
+ response = response + "," + dst;
+
+ return response;
+ }
}

0 comments on commit b1fffaf

Please sign in to comment.