@@ -1496,23 +1496,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1496
1496
reloadSetAutoTimeRequiredUi ();
1497
1497
return true ;
1498
1498
case SET_AUTO_TIME_KEY :
1499
- try {
1500
- ReflectionUtil .invoke (mDevicePolicyManager , "setAutoTime" ,
1501
- new Class <?>[]{ComponentName .class , boolean .class },
1502
- mAdminComponentName , newValue .equals (true ));
1503
- } catch (ReflectionIsTemporaryException e ) {
1504
- Log .e (TAG , "Error invoking setAutoTime" , e );
1505
- }
1499
+ setAutoTimeEnabled (newValue .equals (true ));
1506
1500
reloadSetAutoTimeUi ();
1507
1501
return true ;
1508
1502
case SET_AUTO_TIME_ZONE_KEY :
1509
- try {
1510
- ReflectionUtil .invoke (mDevicePolicyManager , "setAutoTimeZone" ,
1511
- new Class <?>[]{ComponentName .class , boolean .class },
1512
- mAdminComponentName , newValue .equals (true ));
1513
- } catch (ReflectionIsTemporaryException e ) {
1514
- Log .e (TAG , "Error invoking setAutoTimeZone" , e );
1515
- }
1503
+ setAutoTimeZoneEnabled (newValue .equals (true ));
1516
1504
reloadSetAutoTimeZoneUi ();
1517
1505
return true ;
1518
1506
case SET_DEVICE_ORGANIZATION_NAME_KEY :
@@ -2610,26 +2598,14 @@ private void reloadSetAutoTimeRequiredUi() {
2610
2598
2611
2599
@ TargetApi (Util .R_VERSION_CODE )
2612
2600
private void reloadSetAutoTimeUi () {
2613
- try {
2614
- boolean isAutoTime = (Boolean ) ReflectionUtil .invoke (mDevicePolicyManager ,
2615
- "getAutoTimeEnabled" , new Class <?>[]{ComponentName .class },
2616
- mAdminComponentName );
2617
- mSetAutoTimePreference .setChecked (isAutoTime );
2618
- } catch (ReflectionIsTemporaryException e ) {
2619
- Log .e (TAG , "Error invoking getAutoTimeEnabled" , e );
2620
- }
2601
+ boolean isAutoTime = mDevicePolicyManager .getAutoTimeEnabled (mAdminComponentName );
2602
+ mSetAutoTimePreference .setChecked (isAutoTime );
2621
2603
}
2622
2604
2623
2605
@ TargetApi (Util .R_VERSION_CODE )
2624
2606
private void reloadSetAutoTimeZoneUi () {
2625
- try {
2626
- boolean isAutoTimeZone = (Boolean ) ReflectionUtil .invoke (mDevicePolicyManager ,
2627
- "getAutoTimeZoneEnabled" , new Class <?>[]{ComponentName .class },
2628
- mAdminComponentName );
2629
- mSetAutoTimeZonePreference .setChecked (isAutoTimeZone );
2630
- } catch (ReflectionIsTemporaryException e ) {
2631
- Log .e (TAG , "Error invoking getAutoTimeZoneEnabled" , e );
2632
- }
2607
+ boolean isAutoTimeZone = mDevicePolicyManager .getAutoTimeZoneEnabled (mAdminComponentName );
2608
+ mSetAutoTimeZonePreference .setChecked (isAutoTimeZone );
2633
2609
}
2634
2610
2635
2611
@ TargetApi (VERSION_CODES .LOLLIPOP )
@@ -4059,30 +4035,13 @@ abstract static class ManageLockTaskListCallback {
4059
4035
public abstract void onPositiveButtonClicked (String [] lockTaskArray );
4060
4036
}
4061
4037
4038
+ @ RequiresApi (Util .R_VERSION_CODE )
4062
4039
private void setAutoTimeEnabled (boolean enabled ) {
4063
- try {
4064
- ReflectionUtil .invoke (mDevicePolicyManager , "setAutoTimeEnabled" ,
4065
- new Class <?>[]{ComponentName .class , boolean .class },
4066
- mAdminComponentName , enabled );
4067
- } catch (ReflectionIsTemporaryException e ) {
4068
- Log .e (TAG , "Error invoking setAutoTimeEnabled" , e );
4069
- // Prior to R, auto time is controlled by a global setting
4070
- mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
4071
- Settings .Global .AUTO_TIME , enabled ? "1" : "0" );
4072
- }
4040
+ mDevicePolicyManager .setAutoTimeEnabled (mAdminComponentName , enabled );
4073
4041
}
4074
4042
4043
+ @ RequiresApi (Util .R_VERSION_CODE )
4075
4044
private void setAutoTimeZoneEnabled (boolean enabled ) {
4076
- try {
4077
- ReflectionUtil .invoke (mDevicePolicyManager , "setAutoTimeZoneEnabled" ,
4078
- new Class <?>[]{ComponentName .class , boolean .class },
4079
- mAdminComponentName , enabled );
4080
- } catch (ReflectionIsTemporaryException e ) {
4081
- Log .e (TAG , "Error invoking setAutoTimeZoneEnabled" , e );
4082
- // Prior to R, auto timezone is controlled by a global setting
4083
- mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
4084
- Settings .Global .AUTO_TIME_ZONE , enabled ? "1" : "0" );
4085
- }
4086
-
4045
+ mDevicePolicyManager .setAutoTimeZoneEnabled (mAdminComponentName , enabled );
4087
4046
}
4088
4047
}
0 commit comments