Add device/profile app check in background check
If app is device or profile app, we disable the background check
toggle. This cl also create an util method for this check and
remove duplicate code
Bug: 64665807
Test: RunSettingsRoboTests
Change-Id: Id8336eadaac8832327bc3653aaa7dfbacde352ac
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 2a57577..417ac0f 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -107,6 +107,7 @@
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.UserIcons;
import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.enterprise.DevicePolicyManagerWrapper;
import com.android.settings.password.FingerprintManagerWrapper;
import com.android.settings.password.IFingerprintManager;
@@ -1280,6 +1281,28 @@
}
/**
+ * Return {@code true} if the supplied package is device owner or profile owner of at
+ * least one user.
+ * @param userManager used to get profile owner app for each user
+ * @param devicePolicyManager used to check whether it is device owner app
+ * @param packageName package to check about
+ */
+ public static boolean isProfileOrDeviceOwner(UserManager userManager,
+ DevicePolicyManagerWrapper devicePolicyManager, String packageName) {
+ List<UserInfo> userInfos = userManager.getUsers();
+ if (devicePolicyManager.isDeviceOwnerAppOnAnyUser(packageName)) {
+ return true;
+ }
+ for (int i = 0, size = userInfos.size(); i < size; i++) {
+ ComponentName cn = devicePolicyManager.getProfileOwnerAsUser(userInfos.get(i).id);
+ if (cn != null && cn.getPackageName().equals(packageName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Return the resource id to represent the install status for an app
*/
@StringRes