2024年1月21日发(作者:)

public interface Listener { /** * Automatic time detection has been enabled or disabled. */ void onTimeDetectionChange(boolean enabled); /** * Automatic time zone detection has been enabled or disabled. */ void onTimeZoneDetectionChange(boolean enabled); } /** * Sets a listener that will be called when the automatic time / time zone detection setting * changes. */ public void setListener(Listener listener) { if (listener == null) { throw new NullPointerException("listener==null"); } if (mListener != null) { throw new IllegalStateException("listener already set"); } ner = listener; erContentObserver( For(_TIME), true, new ContentObserver(new Handler()) { public void onChange(boolean selfChange) { DetectionChange(isTimeDetectionEnabled()); } }); erContentObserver( For(_TIME_ZONE), true, new ContentObserver(new Handler()) { public void onChange(boolean selfChange) { ZoneDetectionChange(isTimeZoneDetectionEnabled()); } }); }当时区开关改变时候,会有监听函数:onTimeZoneDetectionChange响应;继续跟踪可以找到实现该代码的位置:frameworks/opt/telephony/src/java/com/android/internal/telephony/

+ " lookupResult=" + lookupResult); } zoneId = lookupResult != null ? : null; } } if ((zoneId == null) || mLatestNitzSignal == null || offsetInfoDiffers(newNitzData, )) { // We got the time before the country, or the zone has changed // so we don't know how to identify the DST rules yet. Save // the information and hope to fix it up later. mNeedCountryCodeForNitz = true; mLatestNitzSignal = nitzSignal; } String tmpLog = "handleTimeZoneFromNitz: nitzSignal=" + nitzSignal + " zoneId=" + zoneId + " iso=" + iso + " mGotCountryCode=" + mGotCountryCode + " mNeedCountryCodeForNitz=" + mNeedCountryCodeForNitz + " isTimeZoneDetectionEnabled()=" + ZoneDetectionEnabled(); if (DBG) { Rlog.d(LOG_TAG, tmpLog); } (tmpLog); if (zoneId != null) { if (ZoneDetectionEnabled()) { setAndBroadcastNetworkSetTimeZone(zoneId); } mNitzTimeZoneDetectionSuccessful = true; mSavedTimeZoneId = zoneId; } } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "handleTimeZoneFromNitz: Processing NITZ data" + " nitzSignal=" + nitzSignal + " ex=" + ex); } } private static boolean offsetInfoDiffers(NitzData one, NitzData two) { return alOffsetMillis() != alOffsetMillis() || () != (); } private void handleTimeFromNitz(TimeStampedValue nitzSignal) { try { boolean ignoreNitz = oreNitz(); if (ignoreNitz) { Rlog.d(LOG_TAG, "handleTimeFromNitz: Not setting clock because -nitz is set"); return; } try { // Acquire the wake lock as we are reading the elapsed realtime clock and system // clock. e(); // Validate the nitzTimeSignal to reject obviously bogus elapsedRealtime values. long elapsedRealtime = dRealtime(); long millisSinceNitzReceived = elapsedRealtime - edRealtime; if (millisSinceNitzReceived < 0 || millisSinceNitzReceived > _VALUE) { if (DBG) {

Rlog.d(LOG_TAG, "handleTimeFromNitz: not setting time, unexpected" + " elapsedRealtime=" + elapsedRealtime + " nitzSignal=" + nitzSignal); } return; } // Adjust the NITZ time by the delay since it was received to get the time now. long adjustedCurrentTimeMillis = rentTimeInMillis() + millisSinceNitzReceived; long gained = adjustedCurrentTimeMillis - tTimeMillis(); if (DetectionEnabled()) { String logMsg = "handleTimeFromNitz:" + " nitzSignal=" + nitzSignal + " adjustedCurrentTimeMillis=" + adjustedCurrentTimeMillis + " millisSinceNitzReceived= " + millisSinceNitzReceived + " gained=" + gained; if (mSavedNitzTime == null) { logMsg += ": First update received."; setAndBroadcastNetworkSetTime(logMsg, adjustedCurrentTimeMillis); } else { long elapsedRealtimeSinceLastSaved = dRealtime() - edRealtime; int nitzUpdateSpacing = zUpdateSpacingMillis(); int nitzUpdateDiff = zUpdateDiffMillis(); if (elapsedRealtimeSinceLastSaved > nitzUpdateSpacing || (gained) > nitzUpdateDiff) { // Either it has been a while since we received an update, or the gain // is sufficiently large that we want to act on it. logMsg += ": New update received."; setAndBroadcastNetworkSetTime(logMsg, adjustedCurrentTimeMillis); } else { if (DBG) { Rlog.d(LOG_TAG, logMsg + ": Update throttled."); } // Return early. This means that we don't reset the // mSavedNitzTime for next time and that we may act on more // NITZ time signals overall but should end up with a system clock that // tracks NITZ more closely than if we saved throttled values (which // would reset dRealtime used to calculate time // since the last NITZ signal was received). return; } } } // Save the last NITZ time signal used so we can return to it later // if auto-time detection is toggled. mSavedNitzTime = new TimeStampedValue<>( adjustedCurrentTimeMillis, edRealtime); } finally { e(); } } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "handleTimeFromNitz: Processing NITZ data" + " nitzSignal=" + nitzSignal + " ex=" + ex); } } private void setAndBroadcastNetworkSetTimeZone(String zoneId) { if (DBG) { Rlog.d(LOG_TAG, "setAndBroadcastNetworkSetTimeZone: zoneId=" + zoneId);

@Override public void handleMessage(Message msg) { AsyncResult ar; int[] ints; Message message; if (VDBG) log("received event " + ); switch () { case EVENT_SET_RADIO_POWER_OFF: synchronized(this) { if (mPendingRadioPowerOffAfterDataOff && (1 == mPendingRadioPowerOffAfterDataOffTag)) { if (DBG) log("EVENT_SET_RADIO_OFF, turn radio off now."); hangupAndPowerOff(); mPendingRadioPowerOffAfterDataOffTag += 1; mPendingRadioPowerOffAfterDataOff = false; } else { log("EVENT_SET_RADIO_OFF is stale arg1=" + 1 + "!= tag=" + mPendingRadioPowerOffAfterDataOffTag); } } break;

//省略较多代码.. case EVENT_NITZ_TIME: ar = (AsyncResult) ; String nitzString = (String)((Object[]))[0]; long nitzReceiveTime = ((Long)((Object[]))[1]).longValue(); setTimeFromNITZString(nitzString, nitzReceiveTime); break; case EVENT_SIGNAL_STRENGTH_UPDATE: // This is a notification from ignalStrengthUpdate ar = (AsyncResult) ; // The radio is telling us about signal strength changes // we don't have to ask it mDontPollSignalStrength = true; onSignalStrengthResult(ar); break;public ServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) { mNitzState = tance().makeNitzStateMachine(phone); mPhone = phone; mCi = ci; //省略较多代码 erForImsNetworkStateChanged(this, EVENT_IMS_STATE_CHANGED, null); erForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); ITZTime(this, EVENT_NITZ_TIME, null);frameworks/opt/telephony/src/java/com/android/internal/telephony/

public static TelephonyComponentFactory getInstance() { if (sInstance == null) { String fullClsName = "ephonyComponentFactory"; String libPath = "/system/framework/"; PathClassLoader classLoader = new PathClassLoader(libPath, temClassLoader()); Rlog.d(LOG_TAG, "classLoader = " + classLoader); if (fullClsName == null || () == 0) { Rlog.d(LOG_TAG, "no customized TelephonyPlugin available, fallback to default"); fullClsName = "onyComponentFactory"; } Class cls = null; try { cls = e(fullClsName, false, classLoader); Rlog.d(LOG_TAG, "cls = " + cls); Constructor custMethod = structor(); Rlog.d(LOG_TAG, "constructor method = " + custMethod); sInstance = (TelephonyComponentFactory) tance(); } catch (NoClassDefFoundError e) { tackTrace(); Rlog.e(LOG_TAG, "error loading TelephonyComponentFactory"); sInstance = new TelephonyComponentFactory(); } catch (Exception e) { tackTrace(); Rlog.e(LOG_TAG, "Error loading TelephonyComponentFactory"); sInstance = new TelephonyComponentFactory(); } } return sInstance; } /** * Returns a new {@link NitzStateMachine} instance. */ public NitzStateMachine makeNitzStateMachine(GsmCdmaPhone phone) { return new NitzStateMachine(phone); }frameworks/opt/telephony/src/java/com/android/internal/telephony/