@@ -1265,13 +1265,11 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
1265
1265
return true ;
1266
1266
case SET_TIME_KEY :
1267
1267
// Disable auto time before we could set time manually.
1268
- mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
1269
- Settings .Global .AUTO_TIME , "0" );
1268
+ setAutoTimeEnabled (false );
1270
1269
showSetTimeDialog ();
1271
1270
return true ;
1272
1271
case SET_TIME_ZONE_KEY :
1273
- mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
1274
- Settings .Global .AUTO_TIME_ZONE , "0" );
1272
+ setAutoTimeZoneEnabled (false );
1275
1273
showSetTimeZoneDialog ();
1276
1274
return true ;
1277
1275
case MANAGE_OVERRIDE_APN_KEY :
@@ -4037,4 +4035,31 @@ private boolean isOrganizationOwnedDeviceWithManagedProfile() {
4037
4035
abstract static class ManageLockTaskListCallback {
4038
4036
public abstract void onPositiveButtonClicked (String [] lockTaskArray );
4039
4037
}
4038
+
4039
+ private void setAutoTimeEnabled (boolean enabled ) {
4040
+ try {
4041
+ ReflectionUtil .invoke (mDevicePolicyManager , "setAutoTime" ,
4042
+ new Class <?>[]{ComponentName .class , boolean .class },
4043
+ mAdminComponentName , enabled );
4044
+ } catch (ReflectionIsTemporaryException e ) {
4045
+ Log .e (TAG , "Error invoking setAutoTime" , e );
4046
+ // Prior to R, auto time is controlled by a global setting
4047
+ mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
4048
+ Settings .Global .AUTO_TIME , enabled ? "1" : "0" );
4049
+ }
4050
+ }
4051
+
4052
+ private void setAutoTimeZoneEnabled (boolean enabled ) {
4053
+ try {
4054
+ ReflectionUtil .invoke (mDevicePolicyManager , "setAutoTimeZone" ,
4055
+ new Class <?>[]{ComponentName .class , boolean .class },
4056
+ mAdminComponentName , enabled );
4057
+ } catch (ReflectionIsTemporaryException e ) {
4058
+ Log .e (TAG , "Error invoking setAutoTimeZone" , e );
4059
+ // Prior to R, auto timezone is controlled by a global setting
4060
+ mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
4061
+ Settings .Global .AUTO_TIME_ZONE , enabled ? "1" : "0" );
4062
+ }
4063
+
4064
+ }
4040
4065
}
0 commit comments