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

Commit 4fc5ee4c authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Load admin data in DPMS asynchronously during boot."

parents 5dec8840 c53c47fa
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -175,6 +175,12 @@ public abstract class UsageStatsManagerInternal {
     */
     */
    public abstract void setActiveAdminApps(Set<String> adminApps, int userId);
    public abstract void setActiveAdminApps(Set<String> adminApps, int userId);


    /**
     * Called by DevicePolicyManagerService during boot to inform that admin data is loaded and
     * pushed to UsageStatsService.
     */
    public abstract void onAdminDataAvailable();

    /**
    /**
     * Return usage stats.
     * Return usage stats.
     *
     *
+25 −0
Original line number Original line Diff line number Diff line
@@ -18,11 +18,13 @@ package com.android.internal.util;


import android.os.Process;
import android.os.Process;


import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;


/**
/**
@@ -86,4 +88,27 @@ public class ConcurrentUtils {
        }
        }
    }
    }


    /**
     * Waits for {@link CountDownLatch#countDown()} to be called on the {@param countDownLatch}.
     * <p>If {@link CountDownLatch#countDown()} doesn't occur within {@param timeoutMs}, this
     * method will throw {@code IllegalStateException}
     * <p>If {@code InterruptedException} occurs, this method will interrupt the current thread
     * and throw {@code IllegalStateException}
     *
     * @param countDownLatch the CountDownLatch which {@link CountDownLatch#countDown()} is
     *                       being waited on.
     * @param timeoutMs the maximum time waited for {@link CountDownLatch#countDown()}
     * @param description a short description of the operation
     */
    public static void waitForCountDownNoInterrupt(CountDownLatch countDownLatch, long timeoutMs,
            String description) {
        try {
            if (!countDownLatch.await(timeoutMs, TimeUnit.MILLISECONDS)) {
                throw new IllegalStateException(description + " timed out.");
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException(description + " interrupted.");
        }
    }
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -66,4 +66,9 @@ public abstract class NetworkPolicyManagerInternal {
     * given network.
     * given network.
     */
     */
    public abstract long getSubscriptionOpportunisticQuota(Network network, int quotaType);
    public abstract long getSubscriptionOpportunisticQuota(Network network, int quotaType);

    /**
     * Informs that admin data is loaded and available.
     */
    public abstract void onAdminDataAvailable();
}
}
+25 −0
Original line number Original line Diff line number Diff line
@@ -199,6 +199,7 @@ import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.IndentingPrintWriter;
@@ -333,6 +334,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {


    private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
    private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;


    /**
     * Indicates the maximum wait time for admin data to be available;
     */
    private static final long WAIT_FOR_ADMIN_DATA_TIMEOUT_MS = 10_000;

    private static final int MSG_RULES_CHANGED = 1;
    private static final int MSG_RULES_CHANGED = 1;
    private static final int MSG_METERED_IFACES_CHANGED = 2;
    private static final int MSG_METERED_IFACES_CHANGED = 2;
    private static final int MSG_LIMIT_REACHED = 5;
    private static final int MSG_LIMIT_REACHED = 5;
@@ -384,6 +390,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {


    private final boolean mSuppressDefaultPolicy;
    private final boolean mSuppressDefaultPolicy;


    private final CountDownLatch mAdminDataAvailableLatch = new CountDownLatch(1);

    /** Defined network policies. */
    /** Defined network policies. */
    @GuardedBy("mNetworkPoliciesSecondLock")
    @GuardedBy("mNetworkPoliciesSecondLock")
    final ArrayMap<NetworkTemplate, NetworkPolicy> mNetworkPolicy = new ArrayMap<>();
    final ArrayMap<NetworkTemplate, NetworkPolicy> mNetworkPolicy = new ArrayMap<>();
@@ -672,6 +680,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {


                    mSystemReady = true;
                    mSystemReady = true;


                    waitForAdminData();

                    // read policy from disk
                    // read policy from disk
                    readPolicyAL();
                    readPolicyAL();


@@ -4590,6 +4600,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                return mSubscriptionOpportunisticQuota.get(getSubIdLocked(network));
                return mSubscriptionOpportunisticQuota.get(getSubIdLocked(network));
            }
            }
        }
        }

        @Override
        public void onAdminDataAvailable() {
            mAdminDataAvailableLatch.countDown();
        }
    }
    }


    private int parseSubId(NetworkState state) {
    private int parseSubId(NetworkState state) {
@@ -4617,6 +4632,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        return ArrayUtils.isEmpty(plans) ? null : plans[0];
        return ArrayUtils.isEmpty(plans) ? null : plans[0];
    }
    }


    /**
     * This will only ever be called once - during device boot.
     */
    private void waitForAdminData() {
        if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
            ConcurrentUtils.waitForCountDownNoInterrupt(mAdminDataAvailableLatch,
                    WAIT_FOR_ADMIN_DATA_TIMEOUT_MS, "Wait for admin data");
        }
    }

    private static boolean hasRule(int uidRules, int rule) {
    private static boolean hasRule(int uidRules, int rule) {
        return (uidRules & rule) != 0;
        return (uidRules & rule) != 0;
    }
    }
+0 −6
Original line number Original line Diff line number Diff line
@@ -38,12 +38,6 @@ import java.util.List;
 * should be added here to avoid build breakage in downstream branches.
 * should be added here to avoid build breakage in downstream branches.
 */
 */
abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
    /**
     * To be called by {@link DevicePolicyManagerService#Lifecycle} when the service is started.
     *
     * @see {@link SystemService#onStart}.
     */
    abstract void handleStart();
    /**
    /**
     * To be called by {@link DevicePolicyManagerService#Lifecycle} during the various boot phases.
     * To be called by {@link DevicePolicyManagerService#Lifecycle} during the various boot phases.
     *
     *
Loading