Skip to content

Commit 3f69b93

Browse files
author
Alex Johnston
committed
Remove reflection for time-related DPM APIs in TestDPC
Bug: 152754849 Test: manual testing Change-Id: I50dd2211649a4a5620e11f53e2269a78b29bb2a3
1 parent caae8f2 commit 3f69b93

File tree

1 file changed

+10
-51
lines changed

1 file changed

+10
-51
lines changed

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

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,23 +1496,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
14961496
reloadSetAutoTimeRequiredUi();
14971497
return true;
14981498
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));
15061500
reloadSetAutoTimeUi();
15071501
return true;
15081502
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));
15161504
reloadSetAutoTimeZoneUi();
15171505
return true;
15181506
case SET_DEVICE_ORGANIZATION_NAME_KEY:
@@ -2610,26 +2598,14 @@ private void reloadSetAutoTimeRequiredUi() {
26102598

26112599
@TargetApi(Util.R_VERSION_CODE)
26122600
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);
26212603
}
26222604

26232605
@TargetApi(Util.R_VERSION_CODE)
26242606
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);
26332609
}
26342610

26352611
@TargetApi(VERSION_CODES.LOLLIPOP)
@@ -4059,30 +4035,13 @@ abstract static class ManageLockTaskListCallback {
40594035
public abstract void onPositiveButtonClicked(String[] lockTaskArray);
40604036
}
40614037

4038+
@RequiresApi(Util.R_VERSION_CODE)
40624039
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);
40734041
}
40744042

4043+
@RequiresApi(Util.R_VERSION_CODE)
40754044
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);
40874046
}
40884047
}

0 commit comments

Comments
 (0)