Loading core/java/android/app/timezonedetector/TimeZoneDetector.java +31 −4 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.app.timezonedetector; package android.app.timezonedetector; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SystemService; import android.annotation.SystemService; import android.content.Context; import android.content.Context; import android.os.RemoteException; import android.os.RemoteException; Loading @@ -26,10 +27,11 @@ import android.util.Log; /** /** * The interface through which system components can send signals to the TimeZoneDetectorService. * The interface through which system components can send signals to the TimeZoneDetectorService. * * @hide * @hide */ */ @SystemService(Context.TIME_ZONE_DETECTOR_SERVICE) @SystemService(Context.TIME_ZONE_DETECTOR_SERVICE) public final class TimeZoneDetector { public class TimeZoneDetector { private static final String TAG = "timezonedetector.TimeZoneDetector"; private static final String TAG = "timezonedetector.TimeZoneDetector"; private static final boolean DEBUG = false; private static final boolean DEBUG = false; Loading @@ -41,10 +43,11 @@ public final class TimeZoneDetector { } } /** /** * Suggests the current time zone to the detector. The detector may ignore the signal if better * Suggests the current time zone, determined using telephony signals, to the detector. The * signals are available such as those that come from more reliable sources or were * detector may ignore the signal based on system settings, whether better information is * determined more recently. * available, and so on. */ */ @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE) public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) { public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) { if (DEBUG) { if (DEBUG) { Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion); Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion); Loading @@ -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; } } } services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +10 −1 Original line number Original line Diff line number Diff line Loading @@ -135,6 +135,8 @@ import android.app.admin.SystemUpdatePolicy; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TimeZoneDetector; import android.app.trust.TrustManager; import android.app.trust.TrustManager; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException; Loading Loading @@ -1956,6 +1958,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return mContext.getSystemService(TimeDetector.class); return mContext.getSystemService(TimeDetector.class); } } TimeZoneDetector getTimeZoneDetector() { return mContext.getSystemService(TimeZoneDetector.class); } ConnectivityManager getConnectivityManager() { ConnectivityManager getConnectivityManager() { return mContext.getSystemService(ConnectivityManager.class); return mContext.getSystemService(ConnectivityManager.class); } } Loading Loading @@ -10880,8 +10886,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) { if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) { return false; return false; } } ManualTimeZoneSuggestion manualTimeZoneSuggestion = TimeZoneDetector.createManualTimeZoneSuggestion( timeZone, "DevicePolicyManagerService: setTimeZone"); mInjector.binderWithCleanCallingIdentity(() -> mInjector.binderWithCleanCallingIdentity(() -> mInjector.getAlarmManager().setTimeZone(timeZone)); mInjector.getTimeZoneDetector().suggestManualTimeZone(manualTimeZoneSuggestion)); return true; return true; } } Loading services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.PendingIntent; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TimeZoneDetector; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; Loading Loading @@ -222,6 +223,11 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi return services.timeDetector; return services.timeDetector; } } @Override TimeZoneDetector getTimeZoneDetector() { return services.timeZoneDetector; } @Override @Override LockPatternUtils newLockPatternUtils() { LockPatternUtils newLockPatternUtils() { return services.lockPatternUtils; return services.lockPatternUtils; Loading services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -64,6 +64,8 @@ import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.admin.DevicePolicyManagerInternal; import android.app.admin.PasswordMetrics; import android.app.admin.PasswordMetrics; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.ManualTimeSuggestion; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TimeZoneDetector; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; import android.content.Intent; import android.content.Intent; Loading Loading @@ -3506,7 +3508,9 @@ public class DevicePolicyManagerTest extends DpmTestBase { mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; setupDeviceOwner(); setupDeviceOwner(); dpm.setTimeZone(admin1, "Asia/Shanghai"); 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 { public void testSetTimeZoneFailWithPO() throws Exception { Loading services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.app.IActivityTaskManager; import android.app.NotificationManager; import android.app.NotificationManager; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TimeZoneDetector; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.ContentValues; Loading Loading @@ -109,6 +110,7 @@ public class MockSystemServices { public final AccountManager accountManager; public final AccountManager accountManager; public final AlarmManager alarmManager; public final AlarmManager alarmManager; public final TimeDetector timeDetector; public final TimeDetector timeDetector; public final TimeZoneDetector timeZoneDetector; public final KeyChain.KeyChainConnection keyChainConnection; public final KeyChain.KeyChainConnection keyChainConnection; /** Note this is a partial mock, not a real mock. */ /** Note this is a partial mock, not a real mock. */ public final PackageManager packageManager; public final PackageManager packageManager; Loading Loading @@ -149,6 +151,7 @@ public class MockSystemServices { accountManager = mock(AccountManager.class); accountManager = mock(AccountManager.class); alarmManager = mock(AlarmManager.class); alarmManager = mock(AlarmManager.class); timeDetector = mock(TimeDetector.class); timeDetector = mock(TimeDetector.class); timeZoneDetector = mock(TimeZoneDetector.class); keyChainConnection = mock(KeyChain.KeyChainConnection.class, RETURNS_DEEP_STUBS); keyChainConnection = mock(KeyChain.KeyChainConnection.class, RETURNS_DEEP_STUBS); // Package manager is huge, so we use a partial mock instead. // Package manager is huge, so we use a partial mock instead. Loading Loading
core/java/android/app/timezonedetector/TimeZoneDetector.java +31 −4 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.app.timezonedetector; package android.app.timezonedetector; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SystemService; import android.annotation.SystemService; import android.content.Context; import android.content.Context; import android.os.RemoteException; import android.os.RemoteException; Loading @@ -26,10 +27,11 @@ import android.util.Log; /** /** * The interface through which system components can send signals to the TimeZoneDetectorService. * The interface through which system components can send signals to the TimeZoneDetectorService. * * @hide * @hide */ */ @SystemService(Context.TIME_ZONE_DETECTOR_SERVICE) @SystemService(Context.TIME_ZONE_DETECTOR_SERVICE) public final class TimeZoneDetector { public class TimeZoneDetector { private static final String TAG = "timezonedetector.TimeZoneDetector"; private static final String TAG = "timezonedetector.TimeZoneDetector"; private static final boolean DEBUG = false; private static final boolean DEBUG = false; Loading @@ -41,10 +43,11 @@ public final class TimeZoneDetector { } } /** /** * Suggests the current time zone to the detector. The detector may ignore the signal if better * Suggests the current time zone, determined using telephony signals, to the detector. The * signals are available such as those that come from more reliable sources or were * detector may ignore the signal based on system settings, whether better information is * determined more recently. * available, and so on. */ */ @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE) public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) { public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) { if (DEBUG) { if (DEBUG) { Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion); Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion); Loading @@ -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; } } }
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +10 −1 Original line number Original line Diff line number Diff line Loading @@ -135,6 +135,8 @@ import android.app.admin.SystemUpdatePolicy; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TimeZoneDetector; import android.app.trust.TrustManager; import android.app.trust.TrustManager; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException; Loading Loading @@ -1956,6 +1958,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return mContext.getSystemService(TimeDetector.class); return mContext.getSystemService(TimeDetector.class); } } TimeZoneDetector getTimeZoneDetector() { return mContext.getSystemService(TimeZoneDetector.class); } ConnectivityManager getConnectivityManager() { ConnectivityManager getConnectivityManager() { return mContext.getSystemService(ConnectivityManager.class); return mContext.getSystemService(ConnectivityManager.class); } } Loading Loading @@ -10880,8 +10886,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) { if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) { return false; return false; } } ManualTimeZoneSuggestion manualTimeZoneSuggestion = TimeZoneDetector.createManualTimeZoneSuggestion( timeZone, "DevicePolicyManagerService: setTimeZone"); mInjector.binderWithCleanCallingIdentity(() -> mInjector.binderWithCleanCallingIdentity(() -> mInjector.getAlarmManager().setTimeZone(timeZone)); mInjector.getTimeZoneDetector().suggestManualTimeZone(manualTimeZoneSuggestion)); return true; return true; } } Loading
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.PendingIntent; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TimeZoneDetector; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; Loading Loading @@ -222,6 +223,11 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi return services.timeDetector; return services.timeDetector; } } @Override TimeZoneDetector getTimeZoneDetector() { return services.timeZoneDetector; } @Override @Override LockPatternUtils newLockPatternUtils() { LockPatternUtils newLockPatternUtils() { return services.lockPatternUtils; return services.lockPatternUtils; Loading
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -64,6 +64,8 @@ import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.admin.DevicePolicyManagerInternal; import android.app.admin.PasswordMetrics; import android.app.admin.PasswordMetrics; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.ManualTimeSuggestion; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TimeZoneDetector; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ComponentName; import android.content.Intent; import android.content.Intent; Loading Loading @@ -3506,7 +3508,9 @@ public class DevicePolicyManagerTest extends DpmTestBase { mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; setupDeviceOwner(); setupDeviceOwner(); dpm.setTimeZone(admin1, "Asia/Shanghai"); 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 { public void testSetTimeZoneFailWithPO() throws Exception { Loading
services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.app.IActivityTaskManager; import android.app.NotificationManager; import android.app.NotificationManager; import android.app.backup.IBackupManager; import android.app.backup.IBackupManager; import android.app.timedetector.TimeDetector; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TimeZoneDetector; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.ContentValues; Loading Loading @@ -109,6 +110,7 @@ public class MockSystemServices { public final AccountManager accountManager; public final AccountManager accountManager; public final AlarmManager alarmManager; public final AlarmManager alarmManager; public final TimeDetector timeDetector; public final TimeDetector timeDetector; public final TimeZoneDetector timeZoneDetector; public final KeyChain.KeyChainConnection keyChainConnection; public final KeyChain.KeyChainConnection keyChainConnection; /** Note this is a partial mock, not a real mock. */ /** Note this is a partial mock, not a real mock. */ public final PackageManager packageManager; public final PackageManager packageManager; Loading Loading @@ -149,6 +151,7 @@ public class MockSystemServices { accountManager = mock(AccountManager.class); accountManager = mock(AccountManager.class); alarmManager = mock(AlarmManager.class); alarmManager = mock(AlarmManager.class); timeDetector = mock(TimeDetector.class); timeDetector = mock(TimeDetector.class); timeZoneDetector = mock(TimeZoneDetector.class); keyChainConnection = mock(KeyChain.KeyChainConnection.class, RETURNS_DEEP_STUBS); keyChainConnection = mock(KeyChain.KeyChainConnection.class, RETURNS_DEEP_STUBS); // Package manager is huge, so we use a partial mock instead. // Package manager is huge, so we use a partial mock instead. Loading