Skip to content

Commit 476cf18

Browse files
author
Alex Johnston
committed
Fix BYOD isUsbDataSignalingEnabled failure
* Add device owner and profile owner of org-owned device check. Bug: 186634129 Test: manual testing with TestDPC Change-Id: I254a0113175845a1518cafd77cb97d8fcce7a8b0
1 parent 42a3979 commit 476cf18

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,12 +2758,14 @@ private void reloadCommonCriteriaModeUi() {
27582758

27592759
@TargetApi(VERSION_CODES.S)
27602760
private void reloadEnableUsbDataSignalingUi() {
2761-
try {
2762-
boolean enabled = ReflectionUtil.invoke(mDevicePolicyManager,
2761+
if (isOrganizationOwnedDevice()) {
2762+
try {
2763+
boolean enabled = ReflectionUtil.invoke(mDevicePolicyManager,
27632764
"isUsbDataSignalingEnabled");
2764-
mEnableUsbDataSignalingPreference.setChecked(enabled);
2765-
} catch (ReflectionIsTemporaryException e) {
2766-
Log.e(TAG, "Error invoking isUsbDataSignalingEnabled", e);
2765+
mEnableUsbDataSignalingPreference.setChecked(enabled);
2766+
} catch (ReflectionIsTemporaryException e) {
2767+
Log.e(TAG, "Error invoking isUsbDataSignalingEnabled", e);
2768+
}
27672769
}
27682770
}
27692771

@@ -2793,12 +2795,7 @@ private void reloadSetAutoTimeUi() {
27932795
if (Util.SDK_INT < VERSION_CODES.R) {
27942796
return;
27952797
}
2796-
boolean isOrgOwned =
2797-
mDevicePolicyManagerGateway.isOrganizationOwnedDeviceWithManagedProfile();
2798-
2799-
if (mDevicePolicyManager.isDeviceOwnerApp(mPackageName)
2800-
|| (mDevicePolicyManager.isProfileOwnerApp(mPackageName)
2801-
&& isOrgOwned)) {
2798+
if (isOrganizationOwnedDevice()) {
28022799
boolean isAutoTime = mDevicePolicyManager.getAutoTimeEnabled(mAdminComponentName);
28032800
mSetAutoTimePreference.setChecked(isAutoTime);
28042801
}
@@ -2809,12 +2806,7 @@ private void reloadSetAutoTimeZoneUi() {
28092806
if (Util.SDK_INT < VERSION_CODES.R) {
28102807
return;
28112808
}
2812-
boolean isOrgOwned =
2813-
mDevicePolicyManagerGateway.isOrganizationOwnedDeviceWithManagedProfile();
2814-
2815-
if (mDevicePolicyManager.isDeviceOwnerApp(mPackageName)
2816-
|| (mDevicePolicyManager.isProfileOwnerApp(mPackageName)
2817-
&& isOrgOwned)) {
2809+
if (isOrganizationOwnedDevice()) {
28182810
boolean isAutoTimeZone = mDevicePolicyManager
28192811
.getAutoTimeZoneEnabled(mAdminComponentName);
28202812
mSetAutoTimeZonePreference.setChecked(isAutoTimeZone);
@@ -4345,6 +4337,12 @@ private void factoryResetOrgOwnedDevice() {
43454337
(e) -> onErrorLog("wipeData", e));
43464338
}
43474339

4340+
private boolean isOrganizationOwnedDevice() {
4341+
return mDevicePolicyManager.isDeviceOwnerApp(mPackageName)
4342+
|| (mDevicePolicyManager.isProfileOwnerApp(mPackageName)
4343+
&& mDevicePolicyManagerGateway.isOrganizationOwnedDeviceWithManagedProfile());
4344+
}
4345+
43484346
private int validateDeviceOwnerBeforeO() {
43494347
if (Util.SDK_INT < VERSION_CODES.O) {
43504348
if (!mDevicePolicyManager.isDeviceOwnerApp(mPackageName)) {

0 commit comments

Comments
 (0)