Loading core/java/android/app/usage/UsageStatsManagerInternal.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -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. * * Loading core/java/com/android/internal/util/ConcurrentUtils.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -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; /** /** Loading Loading @@ -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."); } } } } services/core/java/com/android/server/net/NetworkPolicyManagerInternal.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -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(); } } services/core/java/com/android/server/net/NetworkPolicyManagerService.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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<>(); Loading Loading @@ -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(); Loading Loading @@ -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) { Loading Loading @@ -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; } } Loading services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java +0 −6 Original line number Original line Diff line number Diff line Loading @@ -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 Loading
core/java/android/app/usage/UsageStatsManagerInternal.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -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. * * Loading
core/java/com/android/internal/util/ConcurrentUtils.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -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; /** /** Loading Loading @@ -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."); } } } }
services/core/java/com/android/server/net/NetworkPolicyManagerInternal.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -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(); } }
services/core/java/com/android/server/net/NetworkPolicyManagerService.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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<>(); Loading Loading @@ -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(); Loading Loading @@ -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) { Loading Loading @@ -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; } } Loading
services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java +0 −6 Original line number Original line Diff line number Diff line Loading @@ -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