Merge "Fix metrics test flakiness" into tm-dev am: d718e76f47

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17713903

Change-Id: Ifa92e1f72a98ff972ef3d4905816f71eaae932eb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Neil Fuller
2022-04-14 09:57:57 +00:00
committed by Automerger Merge Worker
5 changed files with 44 additions and 2 deletions

View File

@@ -59,6 +59,8 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
*/ */
private static final Set<String> CONFIGURATION_INTERNAL_SERVER_FLAGS_KEYS_TO_WATCH = Set.of( private static final Set<String> CONFIGURATION_INTERNAL_SERVER_FLAGS_KEYS_TO_WATCH = Set.of(
ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED,
ServerFlags.KEY_PRIMARY_LTZP_MODE_OVERRIDE,
ServerFlags.KEY_SECONDARY_LTZP_MODE_OVERRIDE,
ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_RUN_IN_BACKGROUND_ENABLED, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_RUN_IN_BACKGROUND_ENABLED,
ServerFlags.KEY_ENHANCED_METRICS_COLLECTION_ENABLED, ServerFlags.KEY_ENHANCED_METRICS_COLLECTION_ENABLED,
ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT, ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
@@ -443,6 +445,9 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
mTestPrimaryLocationTimeZoneProviderMode = mTestPrimaryLocationTimeZoneProviderMode =
mTestPrimaryLocationTimeZoneProviderPackageName == null mTestPrimaryLocationTimeZoneProviderPackageName == null
? PROVIDER_MODE_DISABLED : PROVIDER_MODE_ENABLED; ? PROVIDER_MODE_DISABLED : PROVIDER_MODE_ENABLED;
// Changing this state can affect the content of ConfigurationInternal, so listeners need to
// be informed.
mContext.getMainThreadHandler().post(this::handleConfigurationInternalChangeOnMainThread);
} }
@Override @Override
@@ -469,6 +474,9 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
mTestSecondaryLocationTimeZoneProviderMode = mTestSecondaryLocationTimeZoneProviderMode =
mTestSecondaryLocationTimeZoneProviderPackageName == null mTestSecondaryLocationTimeZoneProviderPackageName == null
? PROVIDER_MODE_DISABLED : PROVIDER_MODE_ENABLED; ? PROVIDER_MODE_DISABLED : PROVIDER_MODE_ENABLED;
// Changing this state can affect the content of ConfigurationInternal, so listeners need to
// be informed.
mContext.getMainThreadHandler().post(this::handleConfigurationInternalChangeOnMainThread);
} }
@Override @Override
@@ -573,6 +581,10 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
mTestSecondaryLocationTimeZoneProviderPackageName = null; mTestSecondaryLocationTimeZoneProviderPackageName = null;
mTestSecondaryLocationTimeZoneProviderMode = null; mTestSecondaryLocationTimeZoneProviderMode = null;
mRecordStateChangesForTests = false; mRecordStateChangesForTests = false;
// Changing LTZP config can affect the content of ConfigurationInternal, so listeners
// need to be informed.
mContext.getMainThreadHandler().post(this::handleConfigurationInternalChangeOnMainThread);
} }
private boolean isTelephonyFallbackSupported() { private boolean isTelephonyFallbackSupported() {

View File

@@ -336,13 +336,13 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
boolean isTelephonyTimeZoneDetectionSupported() { boolean isTelephonyTimeZoneDetectionSupported() {
enforceManageTimeZoneDetectorPermission(); enforceManageTimeZoneDetectorPermission();
return mServiceConfigAccessor.isTelephonyTimeZoneDetectionFeatureSupported(); return mTimeZoneDetectorStrategy.isTelephonyTimeZoneDetectionSupported();
} }
boolean isGeoTimeZoneDetectionSupported() { boolean isGeoTimeZoneDetectionSupported() {
enforceManageTimeZoneDetectorPermission(); enforceManageTimeZoneDetectorPermission();
return mServiceConfigAccessor.isGeoTimeZoneDetectionFeatureSupported(); return mTimeZoneDetectorStrategy.isGeoTimeZoneDetectionSupported();
} }
/** /**

View File

@@ -124,4 +124,10 @@ public interface TimeZoneDetectorStrategy extends Dumpable {
/** Generates a state snapshot for metrics. */ /** Generates a state snapshot for metrics. */
@NonNull @NonNull
MetricsTimeZoneDetectorState generateMetricsState(); MetricsTimeZoneDetectorState generateMetricsState();
/** Returns {@code true} if the device supports telephony time zone detection. */
boolean isTelephonyTimeZoneDetectionSupported();
/** Returns {@code true} if the device supports geolocation time zone detection. */
boolean isGeoTimeZoneDetectionSupported();
} }

View File

@@ -396,6 +396,20 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
getLatestGeolocationSuggestion()); getLatestGeolocationSuggestion());
} }
@Override
public boolean isTelephonyTimeZoneDetectionSupported() {
synchronized (this) {
return mCurrentConfigurationInternal.isTelephonyDetectionSupported();
}
}
@Override
public boolean isGeoTimeZoneDetectionSupported() {
synchronized (this) {
return mCurrentConfigurationInternal.isGeoDetectionSupported();
}
}
private static int scoreTelephonySuggestion(@NonNull TelephonyTimeZoneSuggestion suggestion) { private static int scoreTelephonySuggestion(@NonNull TelephonyTimeZoneSuggestion suggestion) {
int score; int score;
if (suggestion.getZoneId() == null) { if (suggestion.getZoneId() == null) {

View File

@@ -60,6 +60,16 @@ class FakeTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public boolean isTelephonyTimeZoneDetectionSupported() {
throw new UnsupportedOperationException();
}
@Override
public boolean isGeoTimeZoneDetectionSupported() {
throw new UnsupportedOperationException();
}
@Override @Override
public void dump(IndentingPrintWriter pw, String[] args) { public void dump(IndentingPrintWriter pw, String[] args) {
mDumpCalled = true; mDumpCalled = true;