Fix CTS tests to work on devices without telephony

The tests try to reset the device to have automatic time zone detection
set the way it was before a test ran. It does this by just setting the
value to the original value unconditionally. On devices without any auto
time zone detection mechanisms, i.e. ones without telephony and no
location-based time zone detection, like AOSP and GSI builds, the
time_zone_detector service is smart enough to fail the request to change
the auto detection setting, which causes the test to fail.

As a fix, the test teardown now checks to see if it needs to change the
value and doesn't try if the value is already what is needed.

Bug: 230307604
Bug: 215044363
Test: atest android.time.cts.host.LocationTimeZoneManagerHostTest
Change-Id: Ia955905d3d67a6ec0bf9ac1f56bc2a5938af975e
(cherry picked from commit f2eff834925bf0875d01eaa73b9b78e3008a68c9)
diff --git a/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerHostTest.java b/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerHostTest.java
index 76f4723..b716174 100644
--- a/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerHostTest.java
+++ b/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerHostTest.java
@@ -144,7 +144,10 @@
         mLocationTimeZoneManagerShellHelper.stop();
 
         // Reset settings and server flags as best we can.
-        mTimeZoneDetectorShellHelper.setAutoDetectionEnabled(mOriginalAutoDetectionEnabled);
+        if (mTimeZoneDetectorShellHelper.isAutoDetectionEnabled()
+                != mOriginalAutoDetectionEnabled) {
+            mTimeZoneDetectorShellHelper.setAutoDetectionEnabled(mOriginalAutoDetectionEnabled);
+        }
         mLocationShellHelper.setLocationEnabledForCurrentUser(mOriginalLocationEnabled);
         mDeviceConfigShellHelper.restoreDeviceConfigStateForTest(mDeviceConfigPreTestState);
 
diff --git a/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerStatsTest.java b/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerStatsTest.java
index 0be4769..e591d2d 100644
--- a/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerStatsTest.java
+++ b/hostsidetests/time/host/src/android/time/cts/host/LocationTimeZoneManagerStatsTest.java
@@ -142,7 +142,10 @@
         mLocationTimeZoneManagerShellHelper.stop();
 
         // Reset settings and server flags as best we can.
-        mTimeZoneDetectorShellHelper.setAutoDetectionEnabled(mOriginalAutoDetectionEnabled);
+        if (mTimeZoneDetectorShellHelper.isAutoDetectionEnabled()
+                != mOriginalAutoDetectionEnabled) {
+            mTimeZoneDetectorShellHelper.setAutoDetectionEnabled(mOriginalAutoDetectionEnabled);
+        }
         mLocationShellHelper.setLocationEnabledForCurrentUser(mOriginalLocationEnabled);
 
         ConfigUtils.removeConfig(getDevice());