Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a05ec50 authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Simplify coexistence gating logic

- repurposed the policy engine flag for financed APIs only
- used permission flag for the all other APIs
- removed target sdk logic
- removed coeixstence flag logic

Bug: 273494642
Test: btest a.d.c.DeviceManagementCoexistenceTest
Change-Id: Id3c16654f7d7d766073db7ec427619d7ebdcd784
parent 808497be
Loading
Loading
Loading
Loading
+0 −37
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static android.app.admin.PolicyUpdateResult.RESULT_FAILURE_HARDWARE_LIMIT
import static android.app.admin.PolicyUpdateResult.RESULT_POLICY_CLEARED;
import static android.app.admin.PolicyUpdateResult.RESULT_POLICY_SET;
import static android.content.pm.UserProperties.INHERIT_DEVICE_POLICY_FROM_PARENT;
import static android.provider.DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER;

import android.Manifest;
import android.annotation.NonNull;
@@ -47,7 +46,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.telephony.TelephonyManager;
import android.util.AtomicFile;
import android.util.Log;
@@ -86,9 +84,6 @@ final class DevicePolicyEngine {
            DevicePolicyIdentifiers.getIdentifierForUserRestriction(
                    UserManager.DISALLOW_CELLULAR_2G);

    private static final String ENABLE_COEXISTENCE_FLAG = "enable_coexistence";
    private static final boolean DEFAULT_ENABLE_COEXISTENCE_FLAG = true;

    private final Context mContext;
    private final UserManager mUserManager;

@@ -1152,38 +1147,6 @@ final class DevicePolicyEngine {
        return mEnforcingAdmins.size() > 0;
    }

    /**
     * Returns {@code true} if the coexistence flag is enabled or:
     * <ul>
     * <li>If the provided package is an admin with existing policies
     * <li>A new admin and no other admin have policies set
     * <li>More than one admin have policies set
     */
    boolean canAdminAddPolicies(String packageName, int userId) {
        if (isCoexistenceFlagEnabled()) {
            return true;
        }

        if (mEnforcingAdmins.contains(userId)
                && mEnforcingAdmins.get(userId).stream().anyMatch(admin ->
                admin.getPackageName().equals(packageName))) {
            return true;
        }

        int numOfEnforcingAdmins = 0;
        for (int i = 0; i < mEnforcingAdmins.size(); i++) {
            numOfEnforcingAdmins += mEnforcingAdmins.get(i).size();
        }
        return numOfEnforcingAdmins == 0 || numOfEnforcingAdmins > 1;
    }

    private boolean isCoexistenceFlagEnabled() {
        return DeviceConfig.getBoolean(
                NAMESPACE_DEVICE_POLICY_MANAGER,
                ENABLE_COEXISTENCE_FLAG,
                DEFAULT_ENABLE_COEXISTENCE_FLAG);
    }

    private <V> boolean checkFor2gFailure(@NonNull PolicyDefinition<V> policyDefinition,
            @NonNull EnforcingAdmin enforcingAdmin) {
        if (!policyDefinition.getPolicyKey().getIdentifier().equals(
+68 −156

File changed.

Preview size limit exceeded, changes collapsed.