summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Neil Fuller <nfuller@google.com> 2020-03-31 14:52:09 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-03-31 14:52:09 +0000
commit71271db6bf8842f474278f905ad4cbd032fc849d (patch)
treefa321cbe0fa3780942df3ee6a2c3dee6eeea39a3
parent370d6454d163d06359c96e7972ebe84174ddb01a (diff)
parenta41d012e1a2be58d50255450c3f8630fc3607cb4 (diff)
Merge "Misc tidy up before adding geolocation classes" into rvc-dev
-rw-r--r--core/java/android/app/timezonedetector/ManualTimeZoneSuggestion.java4
-rw-r--r--core/java/android/app/timezonedetector/TimeZoneDetector.java18
-rw-r--r--core/java/android/app/timezonedetector/TimeZoneDetectorImpl.java12
-rw-r--r--core/tests/coretests/src/android/app/timezonedetector/TelephonyTimeZoneSuggestionTest.java2
-rw-r--r--services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java12
-rw-r--r--services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java81
6 files changed, 66 insertions, 63 deletions
diff --git a/core/java/android/app/timezonedetector/ManualTimeZoneSuggestion.java b/core/java/android/app/timezonedetector/ManualTimeZoneSuggestion.java
index 22e2efb1dedd..002c66361233 100644
--- a/core/java/android/app/timezonedetector/ManualTimeZoneSuggestion.java
+++ b/core/java/android/app/timezonedetector/ManualTimeZoneSuggestion.java
@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Objects;
/**
- * A time signal from a manual (user provided) source.
+ * A time zone suggestion from a manual (user provided) source.
*
* <p>{@code zoneId} contains the suggested time zone ID, e.g. "America/Los_Angeles".
*
@@ -124,7 +124,7 @@ public final class ManualTimeZoneSuggestion implements Parcelable {
@Override
public String toString() {
- return "ManualTimeSuggestion{"
+ return "ManualTimeZoneSuggestion{"
+ "mZoneId=" + mZoneId
+ ", mDebugInfo=" + mDebugInfo
+ '}';
diff --git a/core/java/android/app/timezonedetector/TimeZoneDetector.java b/core/java/android/app/timezonedetector/TimeZoneDetector.java
index 20761ad2d447..34a7586192fe 100644
--- a/core/java/android/app/timezonedetector/TimeZoneDetector.java
+++ b/core/java/android/app/timezonedetector/TimeZoneDetector.java
@@ -41,21 +41,21 @@ public interface TimeZoneDetector {
}
/**
- * Suggests the current time zone, determined using telephony signals, to the detector. The
- * detector may ignore the signal based on system settings, whether better information is
- * available, and so on.
+ * Suggests the current time zone, determined using the user's manually entered information, to
+ * the detector. The detector may ignore the signal based on system settings.
*
* @hide
*/
- @RequiresPermission(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE)
- void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion);
+ @RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
+ void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion);
/**
- * Suggests the current time zone, determined for the user's manually information, to the
- * detector. The detector may ignore the signal based on system settings.
+ * Suggests the current time zone, determined using telephony signals, to the detector. The
+ * detector may ignore the signal based on system settings, whether better information is
+ * available, and so on.
*
* @hide
*/
- @RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
- void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion);
+ @RequiresPermission(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE)
+ void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion);
}
diff --git a/core/java/android/app/timezonedetector/TimeZoneDetectorImpl.java b/core/java/android/app/timezonedetector/TimeZoneDetectorImpl.java
index 0ada88500193..54cf1f380d97 100644
--- a/core/java/android/app/timezonedetector/TimeZoneDetectorImpl.java
+++ b/core/java/android/app/timezonedetector/TimeZoneDetectorImpl.java
@@ -40,24 +40,24 @@ public final class TimeZoneDetectorImpl implements TimeZoneDetector {
}
@Override
- public void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion) {
+ public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
if (DEBUG) {
- Log.d(TAG, "suggestTelephonyTimeZone called: " + timeZoneSuggestion);
+ Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);
}
try {
- mITimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
+ mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
- public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
+ public void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion) {
if (DEBUG) {
- Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);
+ Log.d(TAG, "suggestTelephonyTimeZone called: " + timeZoneSuggestion);
}
try {
- mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
+ mITimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/tests/coretests/src/android/app/timezonedetector/TelephonyTimeZoneSuggestionTest.java b/core/tests/coretests/src/android/app/timezonedetector/TelephonyTimeZoneSuggestionTest.java
index c4ff9beec0c5..28009d4168ad 100644
--- a/core/tests/coretests/src/android/app/timezonedetector/TelephonyTimeZoneSuggestionTest.java
+++ b/core/tests/coretests/src/android/app/timezonedetector/TelephonyTimeZoneSuggestionTest.java
@@ -129,7 +129,7 @@ public class TelephonyTimeZoneSuggestionTest {
}
@Test(expected = RuntimeException.class)
- public void testBuilderValidates_emptyZone_badMatchType() {
+ public void testBuilderValidates_nullZone_badMatchType() {
TelephonyTimeZoneSuggestion.Builder builder =
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX);
// No zone ID, so match type should be left unset.
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java
index 0eb27cc5cff0..e0b3ad526f35 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java
@@ -22,9 +22,12 @@ import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import java.io.PrintWriter;
/**
- * The interface for the class that implement the time detection algorithm used by the
+ * The interface for the class that implements the time detection algorithm used by the
* {@link TimeZoneDetectorService}.
*
+ * <p>The strategy uses suggestions to decide whether to modify the device's time zone setting
+ * and what to set it to.
+ *
* <p>Most calls will be handled by a single thread but that is not true for all calls. For example
* {@link #dump(PrintWriter, String[])}) may be called on a different thread so implementations must
* handle thread safety.
@@ -33,7 +36,9 @@ import java.io.PrintWriter;
*/
public interface TimeZoneDetectorStrategy {
- /** Process the suggested manually-entered (i.e. user sourced) time zone. */
+ /**
+ * Suggests a time zone for the device using manually-entered (i.e. user sourced) information.
+ */
void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion suggestion);
/**
@@ -41,8 +46,7 @@ public interface TimeZoneDetectorStrategy {
* {@link TelephonyTimeZoneSuggestion#getZoneId()} is {@code null}. The suggestion is scoped to
* a specific {@link TelephonyTimeZoneSuggestion#getSlotIndex() slotIndex}.
* See {@link TelephonyTimeZoneSuggestion} for an explanation of the metadata associated with a
- * suggestion. The strategy uses suggestions to decide whether to modify the device's time zone
- * setting and what to set it to.
+ * suggestion.
*/
void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion suggestion);
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
index 039c2b4933e9..da34e1b792c1 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
@@ -76,67 +76,67 @@ public class TimeZoneDetectorServiceTest {
}
@Test(expected = SecurityException.class)
- public void testSuggestTelephonyTime_withoutPermission() {
+ public void testSuggestManualTimeZone_withoutPermission() {
doThrow(new SecurityException("Mock"))
- .when(mMockContext).enforceCallingPermission(anyString(), any());
- TelephonyTimeZoneSuggestion timeZoneSuggestion = createTelephonyTimeZoneSuggestion();
+ .when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
+ ManualTimeZoneSuggestion timeZoneSuggestion = createManualTimeZoneSuggestion();
try {
- mTimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
+ mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
fail();
} finally {
- verify(mMockContext).enforceCallingPermission(
- eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
+ verify(mMockContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
anyString());
}
}
@Test
- public void testSuggestTelephonyTimeZone() throws Exception {
- doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
+ public void testSuggestManualTimeZone() throws Exception {
+ doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
- TelephonyTimeZoneSuggestion timeZoneSuggestion = createTelephonyTimeZoneSuggestion();
- mTimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
+ ManualTimeZoneSuggestion timeZoneSuggestion = createManualTimeZoneSuggestion();
+ mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
mTestHandler.assertTotalMessagesEnqueued(1);
- verify(mMockContext).enforceCallingPermission(
- eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
+ verify(mMockContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
anyString());
mTestHandler.waitForMessagesToBeProcessed();
- mStubbedTimeZoneDetectorStrategy.verifySuggestTelephonyTimeZoneCalled(timeZoneSuggestion);
+ mStubbedTimeZoneDetectorStrategy.verifySuggestManualTimeZoneCalled(timeZoneSuggestion);
}
@Test(expected = SecurityException.class)
- public void testSuggestManualTime_withoutPermission() {
+ public void testSuggestTelephonyTimeZone_withoutPermission() {
doThrow(new SecurityException("Mock"))
- .when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
- ManualTimeZoneSuggestion timeZoneSuggestion = createManualTimeZoneSuggestion();
+ .when(mMockContext).enforceCallingPermission(anyString(), any());
+ TelephonyTimeZoneSuggestion timeZoneSuggestion = createTelephonyTimeZoneSuggestion();
try {
- mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
+ mTimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
fail();
} finally {
- verify(mMockContext).enforceCallingOrSelfPermission(
- eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
+ verify(mMockContext).enforceCallingPermission(
+ eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
anyString());
}
}
@Test
- public void testSuggestManualTimeZone() throws Exception {
- doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
+ public void testSuggestTelephonyTimeZone() throws Exception {
+ doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
- ManualTimeZoneSuggestion timeZoneSuggestion = createManualTimeZoneSuggestion();
- mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
+ TelephonyTimeZoneSuggestion timeZoneSuggestion = createTelephonyTimeZoneSuggestion();
+ mTimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
mTestHandler.assertTotalMessagesEnqueued(1);
- verify(mMockContext).enforceCallingOrSelfPermission(
- eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
+ verify(mMockContext).enforceCallingPermission(
+ eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
anyString());
mTestHandler.waitForMessagesToBeProcessed();
- mStubbedTimeZoneDetectorStrategy.verifySuggestManualTimeZoneCalled(timeZoneSuggestion);
+ mStubbedTimeZoneDetectorStrategy.verifySuggestTelephonyTimeZoneCalled(timeZoneSuggestion);
}
@Test
@@ -165,6 +165,10 @@ public class TimeZoneDetectorServiceTest {
mStubbedTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneDetectionChangedCalled();
}
+ private static ManualTimeZoneSuggestion createManualTimeZoneSuggestion() {
+ return new ManualTimeZoneSuggestion("TestZoneId");
+ }
+
private static TelephonyTimeZoneSuggestion createTelephonyTimeZoneSuggestion() {
int slotIndex = 1234;
return new TelephonyTimeZoneSuggestion.Builder(slotIndex)
@@ -174,26 +178,22 @@ public class TimeZoneDetectorServiceTest {
.build();
}
- private static ManualTimeZoneSuggestion createManualTimeZoneSuggestion() {
- return new ManualTimeZoneSuggestion("TestZoneId");
- }
-
private static class StubbedTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
// Call tracking.
- private TelephonyTimeZoneSuggestion mLastTelephonySuggestion;
private ManualTimeZoneSuggestion mLastManualSuggestion;
+ private TelephonyTimeZoneSuggestion mLastTelephonySuggestion;
private boolean mHandleAutoTimeZoneDetectionChangedCalled;
private boolean mDumpCalled;
@Override
- public void suggestTelephonyTimeZone(TelephonyTimeZoneSuggestion timeZoneSuggestion) {
- mLastTelephonySuggestion = timeZoneSuggestion;
+ public void suggestManualTimeZone(ManualTimeZoneSuggestion timeZoneSuggestion) {
+ mLastManualSuggestion = timeZoneSuggestion;
}
@Override
- public void suggestManualTimeZone(ManualTimeZoneSuggestion timeZoneSuggestion) {
- mLastManualSuggestion = timeZoneSuggestion;
+ public void suggestTelephonyTimeZone(TelephonyTimeZoneSuggestion timeZoneSuggestion) {
+ mLastTelephonySuggestion = timeZoneSuggestion;
}
@Override
@@ -207,18 +207,18 @@ public class TimeZoneDetectorServiceTest {
}
void resetCallTracking() {
- mLastTelephonySuggestion = null;
mLastManualSuggestion = null;
+ mLastTelephonySuggestion = null;
mHandleAutoTimeZoneDetectionChangedCalled = false;
mDumpCalled = false;
}
- void verifySuggestTelephonyTimeZoneCalled(TelephonyTimeZoneSuggestion expectedSuggestion) {
- assertEquals(expectedSuggestion, mLastTelephonySuggestion);
+ void verifySuggestManualTimeZoneCalled(ManualTimeZoneSuggestion expectedSuggestion) {
+ assertEquals(expectedSuggestion, mLastManualSuggestion);
}
- public void verifySuggestManualTimeZoneCalled(ManualTimeZoneSuggestion expectedSuggestion) {
- assertEquals(expectedSuggestion, mLastManualSuggestion);
+ void verifySuggestTelephonyTimeZoneCalled(TelephonyTimeZoneSuggestion expectedSuggestion) {
+ assertEquals(expectedSuggestion, mLastTelephonySuggestion);
}
void verifyHandleAutoTimeZoneDetectionChangedCalled() {
@@ -229,5 +229,4 @@ public class TimeZoneDetectorServiceTest {
assertTrue(mDumpCalled);
}
}
-
}