Skip to content

Commit 3d94a97

Browse files
the-felipealAndroid (Google) Code Review
authored andcommitted
Merge "Fixed TestDPC so it doesn't crash when its user is not the device owner." into ub-testdpc-rvc
2 parents d449b75 + 41239dd commit 3d94a97

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class DpcPreferenceHelper {
6262
ADMIN_NONE | ADMIN_DEVICE_OWNER | ADMIN_PROFILE_OWNER | ADMIN_ORG_OWNED_PROFILE_OWNER;
6363
public static final int ADMIN_NOT_NONE = ADMIN_ANY & ~ADMIN_NONE;
6464
public static final @AdminKind int ADMIN_DEFAULT = ADMIN_NOT_NONE;
65-
public static final int NO_CUSTOM_CONSTRIANT = 0;
65+
public static final int NO_CUSTOM_CONSTRAINT = 0;
6666

6767
@Retention(RetentionPolicy.SOURCE)
6868
@IntDef(flag = true, value = {USER_PRIMARY_USER, USER_SECONDARY_USER, USER_MANAGED_PROFILE})
@@ -242,7 +242,7 @@ private CharSequence findConstraintViolation() {
242242

243243
for (CustomConstraint customConstraint : mCustomConstraints) {
244244
@StringRes int strRes = customConstraint.validateConstraint();
245-
if (strRes != NO_CUSTOM_CONSTRIANT) {
245+
if (strRes != NO_CUSTOM_CONSTRAINT) {
246246
return mContext.getString(strRes);
247247
}
248248
}

app/src/main/java/com/afwsamples/testdpc/comp/BindDeviceAdminFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.afwsamples.testdpc.comp;
1818

19-
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT;
19+
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRAINT;
2020

2121
import android.annotation.TargetApi;
2222
import android.app.Activity;
@@ -97,7 +97,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
9797

9898
// Installing certificates makes sense for managed profile and secondary users.
9999
mInstallCaCertificatePreference.setCustomConstraint(
100-
getCustomConstraint(NO_CUSTOM_CONSTRIANT));
100+
getCustomConstraint(NO_CUSTOM_CONSTRAINT));
101101
}
102102

103103
@Override
@@ -116,7 +116,7 @@ private CustomConstraint getCustomConstraint(int secondaryUserConstraint) {
116116
} else if (!isManagedProfileRunning() || !isManagedProfileUnlocked()) {
117117
return R.string.managed_profile_not_running_or_unlocked;
118118
} else {
119-
return NO_CUSTOM_CONSTRIANT;
119+
return NO_CUSTOM_CONSTRAINT;
120120
}
121121
};
122122
}

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.afwsamples.testdpc.policy;
1818

1919
import static android.os.UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES;
20-
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT;
20+
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRAINT;
2121

2222
import android.accessibilityservice.AccessibilityServiceInfo;
2323
import android.accounts.Account;
@@ -631,7 +631,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
631631
mRequestSecurityLogsPreference = (DpcPreference) findPreference(REQUEST_SECURITY_LOGS);
632632
mRequestSecurityLogsPreference.setOnPreferenceClickListener(this);
633633
final CustomConstraint securityLoggingChecker = () -> isSecurityLoggingEnabled()
634-
? NO_CUSTOM_CONSTRIANT
634+
? NO_CUSTOM_CONSTRAINT
635635
: R.string.requires_security_logs;
636636
mRequestSecurityLogsPreference.setCustomConstraint(securityLoggingChecker);
637637
mRequestPreRebootSecurityLogsPreference =
@@ -644,7 +644,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
644644
mRequestNetworkLogsPreference.setOnPreferenceClickListener(this);
645645
mRequestNetworkLogsPreference.setCustomConstraint(
646646
() -> isNetworkLoggingEnabled()
647-
? NO_CUSTOM_CONSTRIANT
647+
? NO_CUSTOM_CONSTRAINT
648648
: R.string.requires_network_logs);
649649
findPreference(SET_ACCESSIBILITY_SERVICES_KEY).setOnPreferenceClickListener(this);
650650
findPreference(SET_INPUT_METHODS_KEY).setOnPreferenceClickListener(this);
@@ -707,7 +707,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
707707
mUserManager.hasUserRestriction(
708708
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY))
709709
? R.string.user_restricted
710-
: NO_CUSTOM_CONSTRIANT);
710+
: NO_CUSTOM_CONSTRAINT);
711711
mInstallNonMarketAppsPreference.setOnPreferenceChangeListener(this);
712712
findPreference(SET_USER_RESTRICTIONS_KEY).setOnPreferenceClickListener(this);
713713
mUserRestrictionsParentPreference = (DpcPreference) findPreference(SET_USER_RESTRICTIONS_PARENT_KEY);
@@ -742,7 +742,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
742742
(DpcPreference) findPreference(BIND_DEVICE_ADMIN_POLICIES);
743743
bindDeviceAdminPreference.setCustomConstraint(
744744
() -> (Util.getBindDeviceAdminTargetUsers(getActivity()).size() == 1)
745-
? NO_CUSTOM_CONSTRIANT
745+
? NO_CUSTOM_CONSTRAINT
746746
: R.string.require_one_po_to_bind);
747747
bindDeviceAdminPreference.setOnPreferenceClickListener(this);
748748

@@ -1609,9 +1609,13 @@ private void setScreenCaptureDisabledOnParent(boolean disabled) {
16091609
parentDpm.setScreenCaptureDisabled(mAdminComponentName, disabled);
16101610
}
16111611

1612+
private boolean isDeviceOwner() {
1613+
return mDevicePolicyManager.isDeviceOwnerApp(mPackageName);
1614+
}
1615+
16121616
@TargetApi(VERSION_CODES.O)
16131617
private boolean isNetworkLoggingEnabled() {
1614-
return mDevicePolicyManager.isNetworkLoggingEnabled(mAdminComponentName);
1618+
return isDeviceOwner() && mDevicePolicyManager.isNetworkLoggingEnabled(mAdminComponentName);
16151619
}
16161620

16171621
@TargetApi(VERSION_CODES.O)
@@ -2496,7 +2500,7 @@ private void reloadCameraDisableOnParentUi() {
24962500
@TargetApi(VERSION_CODES.O)
24972501
private void reloadEnableNetworkLoggingUi() {
24982502
if (mEnableNetworkLoggingPreference.isEnabled()) {
2499-
boolean isNetworkLoggingEnabled = mDevicePolicyManager.isNetworkLoggingEnabled(mAdminComponentName);
2503+
boolean isNetworkLoggingEnabled = isNetworkLoggingEnabled();
25002504
mEnableNetworkLoggingPreference.setChecked(isNetworkLoggingEnabled);
25012505
mRequestNetworkLogsPreference.refreshEnabledState();
25022506
}
@@ -3996,7 +4000,7 @@ private int validateAffiliatedUserAfterP() {
39964000
return R.string.require_affiliated_user;
39974001
}
39984002
}
3999-
return NO_CUSTOM_CONSTRIANT;
4003+
return NO_CUSTOM_CONSTRAINT;
40004004
}
40014005

40024006
@TargetApi(30)
@@ -4012,7 +4016,7 @@ private int validateDeviceOwnerBeforeO() {
40124016
return R.string.requires_device_owner;
40134017
}
40144018
}
4015-
return NO_CUSTOM_CONSTRIANT;
4019+
return NO_CUSTOM_CONSTRAINT;
40164020
}
40174021

40184022
private int validateDeviceOwnerBeforeP() {
@@ -4021,7 +4025,7 @@ private int validateDeviceOwnerBeforeP() {
40214025
return R.string.requires_device_owner;
40224026
}
40234027
}
4024-
return NO_CUSTOM_CONSTRIANT;
4028+
return NO_CUSTOM_CONSTRAINT;
40254029
}
40264030

40274031
private int validateDeviceOwnerBeforeQ() {
@@ -4030,7 +4034,7 @@ private int validateDeviceOwnerBeforeQ() {
40304034
return R.string.requires_device_owner;
40314035
}
40324036
}
4033-
return NO_CUSTOM_CONSTRIANT;
4037+
return NO_CUSTOM_CONSTRAINT;
40344038
}
40354039

40364040
interface ManageLockTaskListCallback {

app/src/main/java/com/afwsamples/testdpc/policy/keyguard/LockScreenPolicyFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.afwsamples.testdpc.policy.keyguard;
1818

19-
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT;
19+
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRAINT;
2020
import static com.afwsamples.testdpc.policy.keyguard.SetTrustAgentConfigFragment.Type;
2121

2222
import android.annotation.TargetApi;
@@ -282,7 +282,7 @@ private void setup(String key, Object adminSetting) {
282282
dpcPref.setCustomConstraint(
283283
() -> Keys.NOT_APPLICABLE_TO_PARENT.contains(key) && isParentProfileInstance()
284284
? R.string.not_for_parent_profile
285-
: NO_CUSTOM_CONSTRIANT
285+
: NO_CUSTOM_CONSTRAINT
286286
);
287287

288288
// We do not allow user to add trust agent config in pre-N devices in managed profile.

app/src/main/java/com/afwsamples/testdpc/policy/keyguard/PasswordConstraintsFragment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
2525
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
2626

27-
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRIANT;
27+
import static com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.NO_CUSTOM_CONSTRAINT;
2828

2929
import android.app.admin.DevicePolicyManager;
3030
import android.content.ComponentName;
@@ -266,13 +266,13 @@ private void setPreferencesConstraint() {
266266
// Minimum length can be set for most qualities
267267
mMinLength.setCustomConstraint(
268268
() -> getDpmGateway().getPasswordQuality() >= PASSWORD_QUALITY_NUMERIC
269-
? NO_CUSTOM_CONSTRIANT
269+
? NO_CUSTOM_CONSTRAINT
270270
: R.string.not_for_password_quality);
271271

272272
// Other minimums are only active for the highest quality
273273
CustomConstraint constraint =
274274
() -> getDpmGateway().getPasswordQuality() == PASSWORD_QUALITY_COMPLEX
275-
? NO_CUSTOM_CONSTRIANT
275+
? NO_CUSTOM_CONSTRAINT
276276
: R.string.not_for_password_quality;
277277
mMinLetters.setCustomConstraint(constraint);
278278
mMinNumeric.setCustomConstraint(constraint);

0 commit comments

Comments
 (0)