Merge "Initialize mCallback in constructor and make it final." am: 2c4a41353a
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1508496 Change-Id: I9cf01ebdba76732b0725c2ac45d36295f5a98f1a
This commit is contained in:
@@ -64,9 +64,8 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
|
|||||||
@NonNull private final TimeDetectorStrategy mTimeDetectorStrategy;
|
@NonNull private final TimeDetectorStrategy mTimeDetectorStrategy;
|
||||||
|
|
||||||
private static TimeDetectorService create(@NonNull Context context) {
|
private static TimeDetectorService create(@NonNull Context context) {
|
||||||
TimeDetectorStrategy timeDetectorStrategy = new TimeDetectorStrategyImpl();
|
TimeDetectorStrategyImpl.Callback callback = new TimeDetectorStrategyCallbackImpl(context);
|
||||||
TimeDetectorStrategyCallbackImpl callback = new TimeDetectorStrategyCallbackImpl(context);
|
TimeDetectorStrategy timeDetectorStrategy = new TimeDetectorStrategyImpl(callback);
|
||||||
timeDetectorStrategy.initialize(callback);
|
|
||||||
|
|
||||||
Handler handler = FgThread.getHandler();
|
Handler handler = FgThread.getHandler();
|
||||||
TimeDetectorService timeDetectorService =
|
TimeDetectorService timeDetectorService =
|
||||||
|
|||||||
@@ -37,46 +37,6 @@ import java.io.PrintWriter;
|
|||||||
*/
|
*/
|
||||||
public interface TimeDetectorStrategy {
|
public interface TimeDetectorStrategy {
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface used by the strategy to interact with the surrounding service.
|
|
||||||
*
|
|
||||||
* <p>Note: Because the system properties-derived value {@link #isAutoTimeDetectionEnabled()}
|
|
||||||
* can be modified independently and from different threads (and processes!). its use is prone
|
|
||||||
* to race conditions. That will be true until the responsibility for setting their values is
|
|
||||||
* moved to {@link TimeDetectorStrategy}. There are similar issues with
|
|
||||||
* {@link #systemClockMillis()} while any process can modify the system clock.
|
|
||||||
*/
|
|
||||||
interface Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The absolute threshold below which the system clock need not be updated. i.e. if setting
|
|
||||||
* the system clock would adjust it by less than this (either backwards or forwards) then it
|
|
||||||
* need not be set.
|
|
||||||
*/
|
|
||||||
int systemClockUpdateThresholdMillis();
|
|
||||||
|
|
||||||
/** Returns true if automatic time detection is enabled. */
|
|
||||||
boolean isAutoTimeDetectionEnabled();
|
|
||||||
|
|
||||||
/** Acquire a suitable wake lock. Must be followed by {@link #releaseWakeLock()} */
|
|
||||||
void acquireWakeLock();
|
|
||||||
|
|
||||||
/** Returns the elapsedRealtimeMillis clock value. */
|
|
||||||
long elapsedRealtimeMillis();
|
|
||||||
|
|
||||||
/** Returns the system clock value. */
|
|
||||||
long systemClockMillis();
|
|
||||||
|
|
||||||
/** Sets the device system clock. The WakeLock must be held. */
|
|
||||||
void setSystemClock(long newTimeMillis);
|
|
||||||
|
|
||||||
/** Release the wake lock acquired by a call to {@link #acquireWakeLock()}. */
|
|
||||||
void releaseWakeLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initialize the strategy. */
|
|
||||||
void initialize(@NonNull Callback callback);
|
|
||||||
|
|
||||||
/** Process the suggested time from telephony sources. */
|
/** Process the suggested time from telephony sources. */
|
||||||
void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
|
void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ import android.util.Slog;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The real implementation of {@link TimeDetectorStrategy.Callback} used on device.
|
* The real implementation of {@link TimeDetectorStrategyImpl.Callback} used on device.
|
||||||
*/
|
*/
|
||||||
public final class TimeDetectorStrategyCallbackImpl implements TimeDetectorStrategy.Callback {
|
public final class TimeDetectorStrategyCallbackImpl implements TimeDetectorStrategyImpl.Callback {
|
||||||
|
|
||||||
private final static String TAG = "timedetector.TimeDetectorStrategyCallbackImpl";
|
private final static String TAG = "timedetector.TimeDetectorStrategyCallbackImpl";
|
||||||
|
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final LocalLog mTimeChangesLog = new LocalLog(30, false /* useLocalTimestamps */);
|
private final LocalLog mTimeChangesLog = new LocalLog(30, false /* useLocalTimestamps */);
|
||||||
|
|
||||||
// @NonNull after initialize()
|
@NonNull
|
||||||
private Callback mCallback;
|
private final Callback mCallback;
|
||||||
|
|
||||||
// Used to store the last time the system clock state was set automatically. It is used to
|
// Used to store the last time the system clock state was set automatically. It is used to
|
||||||
// detect (and log) issues with the realtime clock or whether the clock is being set without
|
// detect (and log) issues with the realtime clock or whether the clock is being set without
|
||||||
@@ -122,8 +122,44 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
private final ReferenceWithHistory<NetworkTimeSuggestion> mLastNetworkSuggestion =
|
private final ReferenceWithHistory<NetworkTimeSuggestion> mLastNetworkSuggestion =
|
||||||
new ReferenceWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE);
|
new ReferenceWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE);
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void initialize(@NonNull Callback callback) {
|
* The interface used by the strategy to interact with the surrounding service.
|
||||||
|
*
|
||||||
|
* <p>Note: Because the system properties-derived value {@link #isAutoTimeDetectionEnabled()}
|
||||||
|
* can be modified independently and from different threads (and processes!), its use is prone
|
||||||
|
* to race conditions. That will be true until the responsibility for setting their values is
|
||||||
|
* moved to {@link TimeDetectorStrategy}. There are similar issues with
|
||||||
|
* {@link #systemClockMillis()} while any process can modify the system clock.
|
||||||
|
*/
|
||||||
|
public interface Callback {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The absolute threshold below which the system clock need not be updated. i.e. if setting
|
||||||
|
* the system clock would adjust it by less than this (either backwards or forwards) then it
|
||||||
|
* need not be set.
|
||||||
|
*/
|
||||||
|
int systemClockUpdateThresholdMillis();
|
||||||
|
|
||||||
|
/** Returns true if automatic time detection is enabled. */
|
||||||
|
boolean isAutoTimeDetectionEnabled();
|
||||||
|
|
||||||
|
/** Acquire a suitable wake lock. Must be followed by {@link #releaseWakeLock()} */
|
||||||
|
void acquireWakeLock();
|
||||||
|
|
||||||
|
/** Returns the elapsedRealtimeMillis clock value. */
|
||||||
|
long elapsedRealtimeMillis();
|
||||||
|
|
||||||
|
/** Returns the system clock value. */
|
||||||
|
long systemClockMillis();
|
||||||
|
|
||||||
|
/** Sets the device system clock. The WakeLock must be held. */
|
||||||
|
void setSystemClock(long newTimeMillis);
|
||||||
|
|
||||||
|
/** Release the wake lock acquired by a call to {@link #acquireWakeLock()}. */
|
||||||
|
void releaseWakeLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeDetectorStrategyImpl(@NonNull Callback callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,10 +226,6 @@ public class TimeDetectorServiceTest {
|
|||||||
private boolean mHandleAutoTimeDetectionChangedCalled;
|
private boolean mHandleAutoTimeDetectionChangedCalled;
|
||||||
private boolean mDumpCalled;
|
private boolean mDumpCalled;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(Callback ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestTelephonyTime(TelephonyTimeSuggestion timeSuggestion) {
|
public void suggestTelephonyTime(TelephonyTimeSuggestion timeSuggestion) {
|
||||||
mLastTelephonySuggestion = timeSuggestion;
|
mLastTelephonySuggestion = timeSuggestion;
|
||||||
|
|||||||
@@ -616,7 +616,7 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
* A fake implementation of TimeDetectorStrategy.Callback. Besides tracking changes and behaving
|
* A fake implementation of TimeDetectorStrategy.Callback. Besides tracking changes and behaving
|
||||||
* like the real thing should, it also asserts preconditions.
|
* like the real thing should, it also asserts preconditions.
|
||||||
*/
|
*/
|
||||||
private static class FakeCallback implements TimeDetectorStrategy.Callback {
|
private static class FakeCallback implements TimeDetectorStrategyImpl.Callback {
|
||||||
private boolean mAutoTimeDetectionEnabled;
|
private boolean mAutoTimeDetectionEnabled;
|
||||||
private boolean mWakeLockAcquired;
|
private boolean mWakeLockAcquired;
|
||||||
private long mElapsedRealtimeMillis;
|
private long mElapsedRealtimeMillis;
|
||||||
@@ -731,9 +731,7 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
|
|
||||||
Script() {
|
Script() {
|
||||||
mFakeCallback = new FakeCallback();
|
mFakeCallback = new FakeCallback();
|
||||||
mTimeDetectorStrategy = new TimeDetectorStrategyImpl();
|
mTimeDetectorStrategy = new TimeDetectorStrategyImpl(mFakeCallback);
|
||||||
mTimeDetectorStrategy.initialize(mFakeCallback);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Script pokeAutoTimeDetectionEnabled(boolean enabled) {
|
Script pokeAutoTimeDetectionEnabled(boolean enabled) {
|
||||||
|
|||||||
Reference in New Issue
Block a user