Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.timedetector; |
| 18 | |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
| 22 | import android.app.AlarmManager; |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 23 | import android.app.timedetector.ManualTimeSuggestion; |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 24 | import android.app.timedetector.PhoneTimeSuggestion; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 25 | import android.content.Intent; |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 26 | import android.util.LocalLog; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 27 | import android.util.Slog; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 28 | import android.util.TimestampedValue; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 29 | |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 30 | import com.android.internal.annotations.GuardedBy; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 31 | import com.android.internal.telephony.TelephonyIntents; |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 32 | import com.android.internal.util.IndentingPrintWriter; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 33 | |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 34 | import java.io.PrintWriter; |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 35 | import java.lang.annotation.Retention; |
| 36 | import java.lang.annotation.RetentionPolicy; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 37 | |
| 38 | /** |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 39 | * An implementation of TimeDetectorStrategy that passes only NITZ suggestions to |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 40 | * {@link AlarmManager}. |
| 41 | * |
| 42 | * <p>Most public methods are marked synchronized to ensure thread safety around internal state. |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 43 | */ |
| 44 | public final class SimpleTimeDetectorStrategy implements TimeDetectorStrategy { |
| 45 | |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 46 | private static final boolean DBG = false; |
| 47 | private static final String LOG_TAG = "SimpleTimeDetectorStrategy"; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 48 | |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 49 | @IntDef({ ORIGIN_PHONE, ORIGIN_MANUAL }) |
| 50 | @Retention(RetentionPolicy.SOURCE) |
| 51 | public @interface Origin {} |
| 52 | |
| 53 | /** Used when a time value originated from a telephony signal. */ |
| 54 | @Origin |
| 55 | private static final int ORIGIN_PHONE = 1; |
| 56 | |
| 57 | /** Used when a time value originated from a user / manual settings. */ |
| 58 | @Origin |
| 59 | private static final int ORIGIN_MANUAL = 2; |
| 60 | |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 61 | /** |
| 62 | * CLOCK_PARANOIA: The maximum difference allowed between the expected system clock time and the |
| 63 | * actual system clock time before a warning is logged. Used to help identify situations where |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 64 | * there is something other than this class setting the system clock automatically. |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 65 | */ |
| 66 | private static final long SYSTEM_CLOCK_PARANOIA_THRESHOLD_MILLIS = 2 * 1000; |
| 67 | |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 68 | // A log for changes made to the system clock and why. |
| 69 | @NonNull private final LocalLog mTimeChangesLog = new LocalLog(30); |
| 70 | |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 71 | // @NonNull after initialize() |
| 72 | private Callback mCallback; |
| 73 | |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 74 | // Last phone suggestion. |
| 75 | @Nullable private PhoneTimeSuggestion mLastPhoneSuggestion; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 76 | |
| 77 | // Information about the last time signal received: Used when toggling auto-time. |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 78 | @Nullable private TimestampedValue<Long> mLastAutoSystemClockTime; |
| 79 | private boolean mLastAutoSystemClockTimeSendNetworkBroadcast; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 80 | |
| 81 | // System clock state. |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 82 | @Nullable private TimestampedValue<Long> mLastAutoSystemClockTimeSet; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 83 | |
| 84 | @Override |
| 85 | public void initialize(@NonNull Callback callback) { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 86 | mCallback = callback; |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 90 | public synchronized void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 91 | // NITZ logic |
| 92 | |
Neil Fuller | 568fd89 | 2019-11-20 14:39:06 +0000 | [diff] [blame] | 93 | // Empty suggestions are just ignored as we don't currently keep track of suggestion origin. |
| 94 | if (timeSuggestion.getUtcTime() == null) { |
| 95 | return; |
| 96 | } |
| 97 | |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 98 | boolean timeSuggestionIsValid = |
| 99 | validateNewPhoneSuggestion(timeSuggestion, mLastPhoneSuggestion); |
| 100 | if (!timeSuggestionIsValid) { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | // Always store the last NITZ value received, regardless of whether we go on to use it to |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 104 | // update the system clock. This is so that we can validate future phone suggestions. |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 105 | mLastPhoneSuggestion = timeSuggestion; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 106 | |
| 107 | // System clock update logic. |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 108 | final TimestampedValue<Long> newUtcTime = timeSuggestion.getUtcTime(); |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 109 | setSystemClockIfRequired(ORIGIN_PHONE, newUtcTime, timeSuggestion); |
| 110 | } |
| 111 | |
| 112 | @Override |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 113 | public synchronized void suggestManualTime(ManualTimeSuggestion timeSuggestion) { |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 114 | final TimestampedValue<Long> newUtcTime = timeSuggestion.getUtcTime(); |
| 115 | setSystemClockIfRequired(ORIGIN_MANUAL, newUtcTime, timeSuggestion); |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 118 | private static boolean validateNewPhoneSuggestion(@NonNull PhoneTimeSuggestion newSuggestion, |
| 119 | @Nullable PhoneTimeSuggestion lastSuggestion) { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 120 | |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 121 | if (lastSuggestion != null) { |
| 122 | long referenceTimeDifference = TimestampedValue.referenceTimeDifference( |
| 123 | newSuggestion.getUtcTime(), lastSuggestion.getUtcTime()); |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 124 | if (referenceTimeDifference < 0 || referenceTimeDifference > Integer.MAX_VALUE) { |
| 125 | // Out of order or bogus. |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 126 | Slog.w(LOG_TAG, "Bad NITZ signal received." |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 127 | + " referenceTimeDifference=" + referenceTimeDifference |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 128 | + " lastSuggestion=" + lastSuggestion |
| 129 | + " newSuggestion=" + newSuggestion); |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 136 | @GuardedBy("this") |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 137 | private void setSystemClockIfRequired( |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 138 | @Origin int origin, TimestampedValue<Long> time, Object cause) { |
| 139 | // Historically, Android has sent a TelephonyIntents.ACTION_NETWORK_SET_TIME broadcast only |
| 140 | // when setting the time using NITZ. |
| 141 | boolean sendNetworkBroadcast = origin == ORIGIN_PHONE; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 142 | |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 143 | boolean isOriginAutomatic = isOriginAutomatic(origin); |
| 144 | if (isOriginAutomatic) { |
| 145 | // Store the last auto time candidate we've seen in all cases so we can set the system |
| 146 | // clock when/if time detection is off but later enabled. |
| 147 | mLastAutoSystemClockTime = time; |
| 148 | mLastAutoSystemClockTimeSendNetworkBroadcast = sendNetworkBroadcast; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 149 | |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 150 | if (!mCallback.isAutoTimeDetectionEnabled()) { |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 151 | if (DBG) { |
| 152 | Slog.d(LOG_TAG, "Auto time detection is not enabled." |
| 153 | + " time=" + time |
| 154 | + ", cause=" + cause); |
| 155 | } |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 156 | return; |
| 157 | } |
| 158 | } else { |
| 159 | if (mCallback.isAutoTimeDetectionEnabled()) { |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 160 | if (DBG) { |
| 161 | Slog.d(LOG_TAG, "Auto time detection is enabled." |
| 162 | + " time=" + time |
| 163 | + ", cause=" + cause); |
| 164 | } |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | mCallback.acquireWakeLock(); |
| 170 | try { |
| 171 | long elapsedRealtimeMillis = mCallback.elapsedRealtimeMillis(); |
| 172 | long actualTimeMillis = mCallback.systemClockMillis(); |
| 173 | |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 174 | if (isOriginAutomatic) { |
| 175 | // CLOCK_PARANOIA : Check to see if this class owns the clock or if something else |
| 176 | // may be setting the clock. |
| 177 | if (mLastAutoSystemClockTimeSet != null) { |
| 178 | long expectedTimeMillis = TimeDetectorStrategy.getTimeAt( |
| 179 | mLastAutoSystemClockTimeSet, elapsedRealtimeMillis); |
| 180 | long absSystemClockDifference = Math.abs(expectedTimeMillis - actualTimeMillis); |
| 181 | if (absSystemClockDifference > SYSTEM_CLOCK_PARANOIA_THRESHOLD_MILLIS) { |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 182 | Slog.w(LOG_TAG, |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 183 | "System clock has not tracked elapsed real time clock. A clock may" |
| 184 | + " be inaccurate or something unexpectedly set the system" |
| 185 | + " clock." |
| 186 | + " elapsedRealtimeMillis=" + elapsedRealtimeMillis |
| 187 | + " expectedTimeMillis=" + expectedTimeMillis |
| 188 | + " actualTimeMillis=" + actualTimeMillis); |
| 189 | } |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 193 | adjustAndSetDeviceSystemClock( |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 194 | time, sendNetworkBroadcast, elapsedRealtimeMillis, actualTimeMillis, cause); |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 195 | } finally { |
| 196 | mCallback.releaseWakeLock(); |
| 197 | } |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 200 | private static boolean isOriginAutomatic(@Origin int origin) { |
| 201 | return origin == ORIGIN_PHONE; |
| 202 | } |
| 203 | |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 204 | @Override |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 205 | public synchronized void handleAutoTimeDetectionChanged() { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 206 | // If automatic time detection is enabled we update the system clock instantly if we can. |
| 207 | // Conversely, if automatic time detection is disabled we leave the clock as it is. |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 208 | boolean enabled = mCallback.isAutoTimeDetectionEnabled(); |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 209 | if (enabled) { |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 210 | if (mLastAutoSystemClockTime != null) { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 211 | // Only send the network broadcast if the last candidate would have caused one. |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 212 | final boolean sendNetworkBroadcast = mLastAutoSystemClockTimeSendNetworkBroadcast; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 213 | |
| 214 | mCallback.acquireWakeLock(); |
| 215 | try { |
| 216 | long elapsedRealtimeMillis = mCallback.elapsedRealtimeMillis(); |
| 217 | long actualTimeMillis = mCallback.systemClockMillis(); |
| 218 | |
| 219 | final String reason = "Automatic time detection enabled."; |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 220 | adjustAndSetDeviceSystemClock(mLastAutoSystemClockTime, sendNetworkBroadcast, |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 221 | elapsedRealtimeMillis, actualTimeMillis, reason); |
| 222 | } finally { |
| 223 | mCallback.releaseWakeLock(); |
| 224 | } |
| 225 | } |
| 226 | } else { |
| 227 | // CLOCK_PARANOIA: We are losing "control" of the system clock so we cannot predict what |
| 228 | // it should be in future. |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 229 | mLastAutoSystemClockTimeSet = null; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | @Override |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 234 | public synchronized void dump(@NonNull PrintWriter pw, @Nullable String[] args) { |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 235 | pw.println("mLastPhoneSuggestion=" + mLastPhoneSuggestion); |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 236 | pw.println("mLastAutoSystemClockTimeSet=" + mLastAutoSystemClockTimeSet); |
| 237 | pw.println("mLastAutoSystemClockTime=" + mLastAutoSystemClockTime); |
| 238 | pw.println("mLastAutoSystemClockTimeSendNetworkBroadcast=" |
| 239 | + mLastAutoSystemClockTimeSendNetworkBroadcast); |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 240 | |
| 241 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
| 242 | |
| 243 | ipw.println("TimeDetectorStrategyImpl logs:"); |
| 244 | ipw.increaseIndent(); // level 1 |
| 245 | |
| 246 | ipw.println("Time change log:"); |
| 247 | ipw.increaseIndent(); // level 2 |
| 248 | mTimeChangesLog.dump(ipw); |
| 249 | ipw.decreaseIndent(); // level 2 |
| 250 | |
| 251 | ipw.decreaseIndent(); // level 1 |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 254 | @GuardedBy("this") |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 255 | private void adjustAndSetDeviceSystemClock( |
| 256 | TimestampedValue<Long> newTime, boolean sendNetworkBroadcast, |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 257 | long elapsedRealtimeMillis, long actualSystemClockMillis, Object cause) { |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 258 | |
| 259 | // Adjust for the time that has elapsed since the signal was received. |
| 260 | long newSystemClockMillis = TimeDetectorStrategy.getTimeAt(newTime, elapsedRealtimeMillis); |
| 261 | |
| 262 | // Check if the new signal would make sufficient difference to the system clock. If it's |
| 263 | // below the threshold then ignore it. |
| 264 | long absTimeDifference = Math.abs(newSystemClockMillis - actualSystemClockMillis); |
| 265 | long systemClockUpdateThreshold = mCallback.systemClockUpdateThresholdMillis(); |
| 266 | if (absTimeDifference < systemClockUpdateThreshold) { |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 267 | if (DBG) { |
| 268 | Slog.d(LOG_TAG, "Not setting system clock. New time and" |
| 269 | + " system clock are close enough." |
| 270 | + " elapsedRealtimeMillis=" + elapsedRealtimeMillis |
| 271 | + " newTime=" + newTime |
| 272 | + " cause=" + cause |
| 273 | + " systemClockUpdateThreshold=" + systemClockUpdateThreshold |
| 274 | + " absTimeDifference=" + absTimeDifference); |
| 275 | } |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 276 | return; |
| 277 | } |
| 278 | |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 279 | mCallback.setSystemClock(newSystemClockMillis); |
| 280 | String logMsg = "Set system clock using time=" + newTime |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 281 | + " cause=" + cause |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 282 | + " elapsedRealtimeMillis=" + elapsedRealtimeMillis |
Neil Fuller | 40cf295 | 2019-11-28 09:47:30 +0000 | [diff] [blame] | 283 | + " newSystemClockMillis=" + newSystemClockMillis; |
| 284 | if (DBG) { |
| 285 | Slog.d(LOG_TAG, logMsg); |
| 286 | } |
| 287 | mTimeChangesLog.log(logMsg); |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 288 | |
| 289 | // CLOCK_PARANOIA : Record the last time this class set the system clock. |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 290 | mLastAutoSystemClockTimeSet = newTime; |
Neil Fuller | 4980bbc | 2018-06-12 21:06:20 +0100 | [diff] [blame] | 291 | |
| 292 | if (sendNetworkBroadcast) { |
| 293 | // Send a broadcast that telephony code used to send after setting the clock. |
| 294 | // TODO Remove this broadcast as soon as there are no remaining listeners. |
| 295 | Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIME); |
| 296 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 297 | intent.putExtra("time", newSystemClockMillis); |
| 298 | mCallback.sendStickyBroadcast(intent); |
| 299 | } |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 300 | } |
| 301 | } |