Merge "NetworkTimeUpdateService: Grab a wakelock when manipulating system time" into mnc-dr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1942be506e
@@ -30,6 +30,7 @@ import android.os.HandlerThread;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.NtpTrustedTime;
|
import android.util.NtpTrustedTime;
|
||||||
@@ -75,6 +76,7 @@ public class NetworkTimeUpdateService {
|
|||||||
private SettingsObserver mSettingsObserver;
|
private SettingsObserver mSettingsObserver;
|
||||||
// The last time that we successfully fetched the NTP time.
|
// The last time that we successfully fetched the NTP time.
|
||||||
private long mLastNtpFetchTime = NOT_SET;
|
private long mLastNtpFetchTime = NOT_SET;
|
||||||
|
private final PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
// Normal polling frequency
|
// Normal polling frequency
|
||||||
private final long mPollingIntervalMs;
|
private final long mPollingIntervalMs;
|
||||||
@@ -104,6 +106,9 @@ public class NetworkTimeUpdateService {
|
|||||||
com.android.internal.R.integer.config_ntpRetry);
|
com.android.internal.R.integer.config_ntpRetry);
|
||||||
mTimeErrorThresholdMs = mContext.getResources().getInteger(
|
mTimeErrorThresholdMs = mContext.getResources().getInteger(
|
||||||
com.android.internal.R.integer.config_ntpThreshold);
|
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 */
|
/** Initialize the receivers and initiate the first NTP request */
|
||||||
@@ -148,7 +153,15 @@ public class NetworkTimeUpdateService {
|
|||||||
private void onPollNetworkTime(int event) {
|
private void onPollNetworkTime(int event) {
|
||||||
// If Automatic time is not set, don't bother.
|
// If Automatic time is not set, don't bother.
|
||||||
if (!isAutomaticTimeRequested()) return;
|
if (!isAutomaticTimeRequested()) return;
|
||||||
|
mWakeLock.acquire();
|
||||||
|
try {
|
||||||
|
onPollNetworkTimeUnderWakeLock(event);
|
||||||
|
} finally {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onPollNetworkTimeUnderWakeLock(int event) {
|
||||||
final long refTime = SystemClock.elapsedRealtime();
|
final long refTime = SystemClock.elapsedRealtime();
|
||||||
// If NITZ time was received less than mPollingIntervalMs time ago,
|
// If NITZ time was received less than mPollingIntervalMs time ago,
|
||||||
// no need to sync to NTP.
|
// no need to sync to NTP.
|
||||||
|
|||||||
Reference in New Issue
Block a user