diff options
author | Thierry Strudel <tstrudel@google.com> | 2015-10-29 14:40:29 -0700 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2015-11-03 14:35:13 -0800 |
commit | 20779c2e62d49ebe1b509acef557b0c92359e6c2 (patch) | |
tree | 4b7c96e52c5bfc7c00f74762a3e552592aac8da6 /services/core/java/com/android/server/NetworkTimeUpdateService.java | |
parent | 7ed23d24370b213abd3bdf258349627ea45d64f5 (diff) | |
download | frameworks_base-20779c2e62d49ebe1b509acef557b0c92359e6c2.zip frameworks_base-20779c2e62d49ebe1b509acef557b0c92359e6c2.tar.gz frameworks_base-20779c2e62d49ebe1b509acef557b0c92359e6c2.tar.bz2 |
NetworkTimeUpdateService: Grab a wakelock when manipulating system time
Bug: 24986869
Change-Id: Iab4e5ce6be0b5279ce85f868037ba256ee62c0ac
Signed-off-by: Thierry Strudel <tstrudel@google.com>
Diffstat (limited to 'services/core/java/com/android/server/NetworkTimeUpdateService.java')
-rw-r--r-- | services/core/java/com/android/server/NetworkTimeUpdateService.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/NetworkTimeUpdateService.java b/services/core/java/com/android/server/NetworkTimeUpdateService.java index a0d305c..3f0664d 100644 --- a/services/core/java/com/android/server/NetworkTimeUpdateService.java +++ b/services/core/java/com/android/server/NetworkTimeUpdateService.java @@ -30,6 +30,7 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.os.SystemClock; +import android.os.PowerManager; import android.provider.Settings; import android.util.Log; import android.util.NtpTrustedTime; @@ -75,6 +76,7 @@ public class NetworkTimeUpdateService { private SettingsObserver mSettingsObserver; // The last time that we successfully fetched the NTP time. private long mLastNtpFetchTime = NOT_SET; + private final PowerManager.WakeLock mWakeLock; // Normal polling frequency private final long mPollingIntervalMs; @@ -104,6 +106,9 @@ public class NetworkTimeUpdateService { com.android.internal.R.integer.config_ntpRetry); mTimeErrorThresholdMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_ntpThreshold); + + mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, TAG); } /** Initialize the receivers and initiate the first NTP request */ @@ -148,7 +153,15 @@ public class NetworkTimeUpdateService { private void onPollNetworkTime(int event) { // If Automatic time is not set, don't bother. if (!isAutomaticTimeRequested()) return; + mWakeLock.acquire(); + try { + onPollNetworkTimeUnderWakeLock(event); + } finally { + mWakeLock.release(); + } + } + private void onPollNetworkTimeUnderWakeLock(int event) { final long refTime = SystemClock.elapsedRealtime(); // If NITZ time was received less than mPollingIntervalMs time ago, // no need to sync to NTP. |