Skip to content

Commit d35fdfb

Browse files
committed
Apps suspension: Use stable API.
Now that the Android R SDK is stable, switch to using the official version of setPersonalAppsSuspended / getPersonalAppsSuspendedReasons rather than using reflection. Test: That it compiles Change-Id: I7f04e0614b1c049175a9291b54e6f6d4b7862d49
1 parent f2bdc59 commit d35fdfb

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -795,37 +795,13 @@ private void maybeUpdateProfileMaxTimeOff() {
795795

796796
@TargetApi(Util.R_VERSION_CODE)
797797
private void reloadPersonalAppsSuspendedUi() {
798-
// TODO: nuke it when R sdk is available
799-
final int PERSONAL_APPS_NOT_SUSPENDED = 0;
800798
if (mSuspendPersonalApps.isEnabled()) {
801-
int suspendReasons = getPersonalAppsSuspensionReasons();
799+
int suspendReasons =
800+
mDevicePolicyManager.getPersonalAppsSuspendedReasons(mAdminComponentName);
802801
mSuspendPersonalApps.setChecked(suspendReasons != 0);
803802
}
804803
}
805804

806-
// TODO: nuke it when R sdk is available.
807-
int getPersonalAppsSuspensionReasons() {
808-
try {
809-
return (Integer) ReflectionUtil.invoke(mDevicePolicyManager,
810-
"getPersonalAppsSuspendedReasons", new Class<?>[]{ComponentName.class},
811-
mAdminComponentName);
812-
} catch (ReflectionIsTemporaryException e) {
813-
logAndShowToast("Error invoking getPersonalAppsSuspendedReasons", e);
814-
return 0;
815-
}
816-
}
817-
818-
// TODO: nuke it when R sdk is available.
819-
void setPersonalAppsSuspended(boolean suspended) {
820-
try {
821-
ReflectionUtil.invoke(mDevicePolicyManager, "setPersonalAppsSuspended",
822-
new Class<?>[]{ComponentName.class, boolean.class},
823-
mAdminComponentName, suspended);
824-
} catch (ReflectionIsTemporaryException e) {
825-
logAndShowToast("Error invoking setPersonalAppsSuspended", e);
826-
}
827-
}
828-
829805
//TODO: nuke it when R sdk is available.
830806
public long getManagedProfileMaximumTimeOff() {
831807
try {
@@ -1555,7 +1531,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
15551531
reloadLocationModeUi();
15561532
return true;
15571533
case SUSPEND_PERSONAL_APPS_KEY:
1558-
setPersonalAppsSuspended((Boolean) newValue);
1534+
mDevicePolicyManager.setPersonalAppsSuspended(
1535+
mAdminComponentName, (Boolean) newValue);
15591536
reloadPersonalAppsSuspendedUi();
15601537
return true;
15611538
case PROFILE_MAX_TIME_OFF_KEY:

0 commit comments

Comments
 (0)