Skip to content

Commit a2cece0

Browse files
committed
Gate check of organization-owned on SDK level
Do not call DevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile unless running on an R device or newer. Test: Manual, flash a device with Android 10, install TestDPC and create a managed profile. Bug: 153322206 Change-Id: Ide7e16174943358a09ba29674e9abdc4b4756e20
1 parent 2c93dee commit a2cece0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ private int getCurrentAdmin() {
257257
if (dpm.isDeviceOwnerApp(packageName)) {
258258
return ADMIN_DEVICE_OWNER;
259259
}
260-
Boolean orgOwned = dpm.isOrganizationOwnedDeviceWithManagedProfile();
261260
if (dpm.isProfileOwnerApp(packageName)) {
261+
Boolean orgOwned = Util.SDK_INT >= VERSION_CODES.R &&
262+
dpm.isOrganizationOwnedDeviceWithManagedProfile();
262263
if (orgOwned) {
263264
return ADMIN_ORG_OWNED_PROFILE_OWNER;
264265
} else {

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,9 +2358,10 @@ private void loadAppFeedbackNotifications() {
23582358

23592359
private void loadAppStatus() {
23602360
final @StringRes int appStatusStringId;
2361-
boolean isOrgOwned = mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile();
2361+
boolean isOrgOwned = Util.SDK_INT >= VERSION_CODES.R &&
2362+
mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile();
23622363
if (mDevicePolicyManager.isProfileOwnerApp(mPackageName)) {
2363-
if (mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()) {
2364+
if (isOrgOwned) {
23642365
appStatusStringId = R.string.this_is_an_org_owned_profile_owner;
23652366
} else {
23662367
appStatusStringId = R.string.this_is_a_profile_owner;
@@ -2598,19 +2599,25 @@ private void reloadSetAutoTimeRequiredUi() {
25982599

25992600
@TargetApi(Util.R_VERSION_CODE)
26002601
private void reloadSetAutoTimeUi() {
2602+
boolean isOrgOwned = Util.SDK_INT >= VERSION_CODES.R &&
2603+
mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile();
2604+
26012605
if (mDevicePolicyManager.isDeviceOwnerApp(mPackageName)
26022606
|| (mDevicePolicyManager.isProfileOwnerApp(mPackageName)
2603-
&& mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile())) {
2607+
&& isOrgOwned)) {
26042608
boolean isAutoTime = mDevicePolicyManager.getAutoTimeEnabled(mAdminComponentName);
26052609
mSetAutoTimePreference.setChecked(isAutoTime);
26062610
}
26072611
}
26082612

26092613
@TargetApi(Util.R_VERSION_CODE)
26102614
private void reloadSetAutoTimeZoneUi() {
2615+
boolean isOrgOwned = Util.SDK_INT >= VERSION_CODES.R &&
2616+
mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile();
2617+
26112618
if (mDevicePolicyManager.isDeviceOwnerApp(mPackageName)
26122619
|| (mDevicePolicyManager.isProfileOwnerApp(mPackageName)
2613-
&& mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile())) {
2620+
&& isOrgOwned)) {
26142621
boolean isAutoTimeZone = mDevicePolicyManager
26152622
.getAutoTimeZoneEnabled(mAdminComponentName);
26162623
mSetAutoTimeZonePreference.setChecked(isAutoTimeZone);

0 commit comments

Comments
 (0)