diff options
| author | 2019-12-05 06:45:14 -0800 | |
|---|---|---|
| committer | 2019-12-05 06:45:14 -0800 | |
| commit | 6d1e81ee347d3ba9394452a8ec59fdfdc25eedfc (patch) | |
| tree | 824c1a2229d80b715c96f10ded539a37f4e7f905 | |
| parent | 1f6640123b73083769fcede4cb174e7e22a88e6f (diff) | |
| parent | ee036c7535937c411f955c003a019897ec0fbc32 (diff) | |
Merge "Add suggestManualTimeZoneSuggestion to the client" am: 63d5f12489 am: 2447fe6f69
am: ee036c7535
Change-Id: Ia6481faf3520b01d5d1ee821362d6c739479b42c
5 files changed, 55 insertions, 6 deletions
diff --git a/core/java/android/app/timezonedetector/TimeZoneDetector.java b/core/java/android/app/timezonedetector/TimeZoneDetector.java index 909cbc2ccdf7..387a36bba608 100644 --- a/core/java/android/app/timezonedetector/TimeZoneDetector.java +++ b/core/java/android/app/timezonedetector/TimeZoneDetector.java @@ -17,6 +17,7 @@ package android.app.timezonedetector; import android.annotation.NonNull; +import android.annotation.RequiresPermission; import android.annotation.SystemService; import android.content.Context; import android.os.RemoteException; @@ -26,10 +27,11 @@ import android.util.Log; /** * The interface through which system components can send signals to the TimeZoneDetectorService. + * * @hide */ @SystemService(Context.TIME_ZONE_DETECTOR_SERVICE) -public final class TimeZoneDetector { +public class TimeZoneDetector { private static final String TAG = "timezonedetector.TimeZoneDetector"; private static final boolean DEBUG = false; @@ -41,10 +43,11 @@ public final class TimeZoneDetector { } /** - * Suggests the current time zone to the detector. The detector may ignore the signal if better - * signals are available such as those that come from more reliable sources or were - * determined more recently. + * 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. */ + @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE) public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) { if (DEBUG) { Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion); @@ -56,4 +59,28 @@ public final class TimeZoneDetector { } } + /** + * 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. + */ + @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE) + public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) { + if (DEBUG) { + Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion); + } + try { + mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * A shared utility method to create a {@link ManualTimeZoneSuggestion}. + */ + public static ManualTimeZoneSuggestion createManualTimeZoneSuggestion(String tzId, String why) { + ManualTimeZoneSuggestion suggestion = new ManualTimeZoneSuggestion(tzId); + suggestion.addDebugInfo(why); + return suggestion; + } } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 2499ad816b2d..dc70f4af8463 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -139,6 +139,8 @@ import android.app.admin.SystemUpdatePolicy; import android.app.backup.IBackupManager; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.TimeDetector; +import android.app.timezonedetector.ManualTimeZoneSuggestion; +import android.app.timezonedetector.TimeZoneDetector; import android.app.trust.TrustManager; import android.app.usage.UsageStatsManagerInternal; import android.compat.annotation.ChangeId; @@ -1962,6 +1964,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return mContext.getSystemService(TimeDetector.class); } + TimeZoneDetector getTimeZoneDetector() { + return mContext.getSystemService(TimeZoneDetector.class); + } + ConnectivityManager getConnectivityManager() { return mContext.getSystemService(ConnectivityManager.class); } @@ -11123,8 +11129,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) { return false; } + ManualTimeZoneSuggestion manualTimeZoneSuggestion = + TimeZoneDetector.createManualTimeZoneSuggestion( + timeZone, "DevicePolicyManagerService: setTimeZone"); mInjector.binderWithCleanCallingIdentity(() -> - mInjector.getAlarmManager().setTimeZone(timeZone)); + mInjector.getTimeZoneDetector().suggestManualTimeZone(manualTimeZoneSuggestion)); return true; } diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java index f86bacf67901..ac555fda2204 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java @@ -23,6 +23,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.backup.IBackupManager; import android.app.timedetector.TimeDetector; +import android.app.timezonedetector.TimeZoneDetector; import android.app.usage.UsageStatsManagerInternal; import android.content.Context; import android.content.Intent; @@ -235,6 +236,11 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi } @Override + TimeZoneDetector getTimeZoneDetector() { + return services.timeZoneDetector; + } + + @Override LockPatternUtils newLockPatternUtils() { return services.lockPatternUtils; } diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index 059002094bc0..2bfac2c0aa9b 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -64,6 +64,8 @@ import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.admin.PasswordMetrics; import android.app.timedetector.ManualTimeSuggestion; +import android.app.timezonedetector.ManualTimeZoneSuggestion; +import android.app.timezonedetector.TimeZoneDetector; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Intent; @@ -3694,7 +3696,9 @@ public class DevicePolicyManagerTest extends DpmTestBase { mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; setupDeviceOwner(); dpm.setTimeZone(admin1, "Asia/Shanghai"); - verify(getServices().alarmManager).setTimeZone("Asia/Shanghai"); + ManualTimeZoneSuggestion suggestion = + TimeZoneDetector.createManualTimeZoneSuggestion("Asia/Shanghai", "Test debug info"); + verify(getServices().timeZoneDetector).suggestManualTimeZone(suggestion); } public void testSetTimeZoneFailWithPO() throws Exception { diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java index c9273642635e..6a0d9265f594 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java @@ -32,6 +32,7 @@ import android.app.IActivityTaskManager; import android.app.NotificationManager; import android.app.backup.IBackupManager; import android.app.timedetector.TimeDetector; +import android.app.timezonedetector.TimeZoneDetector; import android.app.usage.UsageStatsManagerInternal; import android.content.BroadcastReceiver; import android.content.ContentValues; @@ -113,6 +114,7 @@ public class MockSystemServices { public final AccountManager accountManager; public final AlarmManager alarmManager; public final TimeDetector timeDetector; + public final TimeZoneDetector timeZoneDetector; public final KeyChain.KeyChainConnection keyChainConnection; /** Note this is a partial mock, not a real mock. */ public final PackageManager packageManager; @@ -155,6 +157,7 @@ public class MockSystemServices { accountManager = mock(AccountManager.class); alarmManager = mock(AlarmManager.class); timeDetector = mock(TimeDetector.class); + timeZoneDetector = mock(TimeZoneDetector.class); keyChainConnection = mock(KeyChain.KeyChainConnection.class, RETURNS_DEEP_STUBS); // Package manager is huge, so we use a partial mock instead. |