102
102
import com .afwsamples .testdpc .common .CertificateUtil ;
103
103
import com .afwsamples .testdpc .common .MediaDisplayFragment ;
104
104
import com .afwsamples .testdpc .common .PackageInstallationUtils ;
105
- import com .afwsamples .testdpc .common .ReflectionUtil ;
106
- import com .afwsamples .testdpc .common .ReflectionUtil .ReflectionIsTemporaryException ;
107
105
import com .afwsamples .testdpc .common .UserArrayAdapter ;
108
106
import com .afwsamples .testdpc .common .Util ;
109
107
import com .afwsamples .testdpc .common .preference .CustomConstraint ;
@@ -789,7 +787,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
789
787
private void maybeUpdateProfileMaxTimeOff () {
790
788
if (mProfileMaxTimeOff .isEnabled ()) {
791
789
final String currentValueAsString = Long .toString (
792
- TimeUnit .MILLISECONDS .toSeconds (getManagedProfileMaximumTimeOff ()));
790
+ TimeUnit .MILLISECONDS .toSeconds (
791
+ mDevicePolicyManager .getManagedProfileMaximumTimeOff (mAdminComponentName )));
793
792
mProfileMaxTimeOff .setText (currentValueAsString );
794
793
mProfileMaxTimeOff .setSummary (currentValueAsString );
795
794
}
@@ -804,29 +803,6 @@ private void reloadPersonalAppsSuspendedUi() {
804
803
}
805
804
}
806
805
807
- //TODO: nuke it when R sdk is available.
808
- public long getManagedProfileMaximumTimeOff () {
809
- try {
810
- return (Long ) ReflectionUtil .invoke (mDevicePolicyManager ,
811
- "getManagedProfileMaximumTimeOff" , new Class <?>[]{ComponentName .class },
812
- mAdminComponentName );
813
- } catch (ReflectionIsTemporaryException e ) {
814
- logAndShowToast ("Error invoking getManagedProfileMaximumTimeOff" , e );
815
- return 0 ;
816
- }
817
- }
818
-
819
- //TODO: nuke it when R sdk is available.
820
- public void setManagedProfileMaximumTimeOff (long timeoutMs ) {
821
- try {
822
- ReflectionUtil .invoke (mDevicePolicyManager , "setManagedProfileMaximumTimeOff" ,
823
- new Class <?>[]{ComponentName .class , long .class },
824
- mAdminComponentName , timeoutMs );
825
- } catch (ReflectionIsTemporaryException e ) {
826
- logAndShowToast ("Error invoking setManagedProfileMaximumTimeOff" , e );
827
- }
828
- }
829
-
830
806
private void logAndShowToast (String message , Exception e ) {
831
807
Log .e (TAG , message , e );
832
808
showToast (message + ": " + e .getMessage ());
@@ -1453,14 +1429,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1453
1429
updateStayOnWhilePluggedInPreference ();
1454
1430
return true ;
1455
1431
case WIFI_CONFIG_LOCKDOWN_ENABLE_KEY :
1456
- try {
1457
- ReflectionUtil .invoke (mDevicePolicyManager ,
1458
- "setConfiguredNetworksLockdownState" ,
1459
- new Class <?>[]{ComponentName .class , boolean .class },
1460
- mAdminComponentName , newValue .equals (true ));
1461
- } catch (ReflectionIsTemporaryException e ) {
1462
- Log .e (TAG , "Error invoking setConfiguredNetworksLockdownState" , e );
1463
- }
1432
+ mDevicePolicyManager .setConfiguredNetworksLockdownState (
1433
+ mAdminComponentName , newValue .equals (true ));
1464
1434
reloadLockdownAdminConfiguredNetworksUi ();
1465
1435
return true ;
1466
1436
case INSTALL_NONMARKET_APPS_KEY :
@@ -1511,13 +1481,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1511
1481
editor .commit ();
1512
1482
return true ;
1513
1483
case SET_LOCATION_ENABLED_KEY :
1514
- try {
1515
- ReflectionUtil .invoke (mDevicePolicyManager , "setLocationEnabled" ,
1516
- new Class <?>[]{ComponentName .class , boolean .class },
1517
- mAdminComponentName , newValue .equals (true ));
1518
- } catch (ReflectionIsTemporaryException e ) {
1519
- Log .e (TAG , "Error invoking setLocationEnabled" , e );
1520
- }
1484
+ mDevicePolicyManager .setLocationEnabled (mAdminComponentName , newValue .equals (true ));
1521
1485
reloadLocationEnabledUi ();
1522
1486
reloadLocationModeUi ();
1523
1487
return true ;
@@ -1540,7 +1504,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1540
1504
return true ;
1541
1505
case PROFILE_MAX_TIME_OFF_KEY :
1542
1506
final long timeoutSec = Long .parseLong ((String ) newValue );
1543
- setManagedProfileMaximumTimeOff (TimeUnit .SECONDS .toMillis (timeoutSec ));
1507
+ mDevicePolicyManager .setManagedProfileMaximumTimeOff (
1508
+ mAdminComponentName , TimeUnit .SECONDS .toMillis (timeoutSec ));
1544
1509
maybeUpdateProfileMaxTimeOff ();
1545
1510
return true ;
1546
1511
}
@@ -2457,14 +2422,9 @@ private void reloadLocationEnabledUi() {
2457
2422
2458
2423
@ TargetApi (Util .R_VERSION_CODE )
2459
2424
private void reloadLockdownAdminConfiguredNetworksUi () {
2460
- try {
2461
- boolean lockdown = (Boolean ) ReflectionUtil .invoke (mDevicePolicyManager ,
2462
- "hasLockdownAdminConfiguredNetworks" ,
2463
- new Class <?>[]{ComponentName .class }, mAdminComponentName );
2464
- mLockdownAdminConfiguredNetworksPreference .setChecked (lockdown );
2465
- } catch (ReflectionIsTemporaryException e ) {
2466
- Log .e (TAG , "Error invoking hasLockdownAdminConfiguredNetworks" , e );
2467
- }
2425
+ boolean lockdown = mDevicePolicyManager .hasLockdownAdminConfiguredNetworks (
2426
+ mAdminComponentName );
2427
+ mLockdownAdminConfiguredNetworksPreference .setChecked (lockdown );
2468
2428
}
2469
2429
2470
2430
static private int parseInt (String str , int defaultValue ) {
0 commit comments