Skip to content

Commit 7ef6e6d

Browse files
committed
Is organization-owned: Use stable API
Switch from using reflection to using the official R method, isOrganizationOwnedDeviceWithManagedProfile, now that TestDPC compiles against R. Test: Manual Change-Id: I796e4fc8ee6f7bcb77f94abd5cc4225ed6503d25
1 parent 9abe9d9 commit 7ef6e6d

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

app/src/main/java/com/afwsamples/testdpc/common/preference/DpcPreferenceHelper.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,7 @@ private int getCurrentAdmin() {
257257
if (dpm.isDeviceOwnerApp(packageName)) {
258258
return ADMIN_DEVICE_OWNER;
259259
}
260-
Boolean orgOwned;
261-
try {
262-
orgOwned = (Boolean) ReflectionUtil.invoke(dpm,
263-
"isOrganizationOwnedDeviceWithManagedProfile");
264-
} catch (ReflectionIsTemporaryException e) {
265-
orgOwned = false;
266-
}
260+
Boolean orgOwned = dpm.isOrganizationOwnedDeviceWithManagedProfile();
267261
if (dpm.isProfileOwnerApp(packageName)) {
268262
if (orgOwned) {
269263
return ADMIN_ORG_OWNED_PROFILE_OWNER;

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,8 +2370,9 @@ private void loadAppFeedbackNotifications() {
23702370

23712371
private void loadAppStatus() {
23722372
final @StringRes int appStatusStringId;
2373+
boolean isOrgOwned = mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile();
23732374
if (mDevicePolicyManager.isProfileOwnerApp(mPackageName)) {
2374-
if (isOrganizationOwnedDeviceWithManagedProfile()) {
2375+
if (mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()) {
23752376
appStatusStringId = R.string.this_is_an_org_owned_profile_owner;
23762377
} else {
23772378
appStatusStringId = R.string.this_is_a_profile_owner;
@@ -4054,17 +4055,6 @@ private int validateDeviceOwnerBeforeQ() {
40544055
return NO_CUSTOM_CONSTRIANT;
40554056
}
40564057

4057-
// TODO: nuke it when R sdk is available
4058-
private boolean isOrganizationOwnedDeviceWithManagedProfile() {
4059-
try {
4060-
return (Boolean) ReflectionUtil.invoke(
4061-
mDevicePolicyManager, "isOrganizationOwnedDeviceWithManagedProfile");
4062-
} catch (ReflectionIsTemporaryException e) {
4063-
Log.e(TAG, "Error invoking isOrganizationOwnedDeviceWithManagedProfile", e);
4064-
return false;
4065-
}
4066-
}
4067-
40684058
abstract static class ManageLockTaskListCallback {
40694059
public abstract void onPositiveButtonClicked(String[] lockTaskArray);
40704060
}

0 commit comments

Comments
 (0)