Skip to content

Commit a6b4411

Browse files
committed
Remove use of reflection
Now that R SDK is finalized, there's no need to use reflection anymore. Test: That it compiles. Change-Id: I7ad212ce729b263facf3073f349d220c93d1fe70
1 parent 23ad988 commit a6b4411

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@
102102
import com.afwsamples.testdpc.common.CertificateUtil;
103103
import com.afwsamples.testdpc.common.MediaDisplayFragment;
104104
import com.afwsamples.testdpc.common.PackageInstallationUtils;
105-
import com.afwsamples.testdpc.common.ReflectionUtil;
106-
import com.afwsamples.testdpc.common.ReflectionUtil.ReflectionIsTemporaryException;
107105
import com.afwsamples.testdpc.common.UserArrayAdapter;
108106
import com.afwsamples.testdpc.common.Util;
109107
import com.afwsamples.testdpc.common.preference.CustomConstraint;
@@ -789,7 +787,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
789787
private void maybeUpdateProfileMaxTimeOff() {
790788
if (mProfileMaxTimeOff.isEnabled()) {
791789
final String currentValueAsString = Long.toString(
792-
TimeUnit.MILLISECONDS.toSeconds(getManagedProfileMaximumTimeOff()));
790+
TimeUnit.MILLISECONDS.toSeconds(
791+
mDevicePolicyManager.getManagedProfileMaximumTimeOff(mAdminComponentName)));
793792
mProfileMaxTimeOff.setText(currentValueAsString);
794793
mProfileMaxTimeOff.setSummary(currentValueAsString);
795794
}
@@ -804,29 +803,6 @@ private void reloadPersonalAppsSuspendedUi() {
804803
}
805804
}
806805

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-
830806
private void logAndShowToast(String message, Exception e) {
831807
Log.e(TAG, message, e);
832808
showToast(message + ": " + e.getMessage());
@@ -1453,14 +1429,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
14531429
updateStayOnWhilePluggedInPreference();
14541430
return true;
14551431
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));
14641434
reloadLockdownAdminConfiguredNetworksUi();
14651435
return true;
14661436
case INSTALL_NONMARKET_APPS_KEY:
@@ -1511,13 +1481,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
15111481
editor.commit();
15121482
return true;
15131483
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));
15211485
reloadLocationEnabledUi();
15221486
reloadLocationModeUi();
15231487
return true;
@@ -1540,7 +1504,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
15401504
return true;
15411505
case PROFILE_MAX_TIME_OFF_KEY:
15421506
final long timeoutSec = Long.parseLong((String) newValue);
1543-
setManagedProfileMaximumTimeOff(TimeUnit.SECONDS.toMillis(timeoutSec));
1507+
mDevicePolicyManager.setManagedProfileMaximumTimeOff(
1508+
mAdminComponentName, TimeUnit.SECONDS.toMillis(timeoutSec));
15441509
maybeUpdateProfileMaxTimeOff();
15451510
return true;
15461511
}
@@ -2457,14 +2422,9 @@ private void reloadLocationEnabledUi() {
24572422

24582423
@TargetApi(Util.R_VERSION_CODE)
24592424
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);
24682428
}
24692429

24702430
static private int parseInt(String str, int defaultValue) {

0 commit comments

Comments
 (0)