Android 时间更新机制之RIL更新时间

来源:互联网 发布:山海经真实性知乎 编辑:程序博客网 时间:2024/06/05 11:42

1、RIL.java
CdmaServiceStateTracker以及GsmServiceStateTracker,在系统启动时,会调用如下方式,该方法将Tracher中的Handler与RIL中的上报消息绑定在一起,即收到上报消息,就回调Handler中的某些方法。

    @Override public void    setOnNITZTime(Handler h, int what, Object obj) {        super.setOnNITZTime(h, what, obj);        // Send the last NITZ time if we have it        if (mLastNITZTimeInfo != null) {            mNITZTimeRegistrant                .notifyRegistrant(                    new AsyncResult (null, mLastNITZTimeInfo, null));        }    }

2、CdmaServiceStateTracker.java
调用方式如下:

    protected CdmaServiceStateTracker(CDMAPhone phone, CellInfo cellInfo) {        super(phone, phone.mCi, cellInfo);        mPhone = phone;        mCr = phone.getContext().getContentResolver();        mCi.setOnNITZTime(this, EVENT_NITZ_TIME, null);        ... ...         }

3、RIL.java
RIL在收到上报消息RIL_UNSOL_NITZ_TIME_RECEIVED,后,会调用2中的Handler,发送EVENT_NITZ_TIME的消息。

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));                    }                    // in case NITZ time registrant isn't registered yet, or a new registrant                    // registers later                    mLastNITZTimeInfo = result;                }

4、CdmaServiceStateTracker.java

        case EVENT_NITZ_TIME:            ar = (AsyncResult) msg.obj;            String nitzString = (String)((Object[])ar.result)[0];            long nitzReceiveTime = ((Long)((Object[])ar.result)[1]).longValue();            setTimeFromNITZString(nitzString, nitzReceiveTime);            break;

调用setTimeFromNITZString 去设置时间和时区(偏移值+国家码)。

0 0
原创粉丝点击