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

Commit 90305697 authored by Robert Horvath's avatar Robert Horvath Committed by Android (Google) Code Review
Browse files

Merge "Block network access in Low Power Standby"

parents 0ab1cb1b 452ab99d
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -176,6 +176,9 @@ public class NetworkPolicyManager {
    public static final int FOREGROUND_THRESHOLD_STATE =
            ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;

    /** @hide */
    public static final int TOP_THRESHOLD_STATE = ActivityManager.PROCESS_STATE_BOUND_TOP;

    /**
     * {@link Intent} extra that indicates which {@link NetworkTemplate} rule it
     * applies to.
@@ -246,6 +249,20 @@ public class NetworkPolicyManager {
     * @hide
     */
    public static final int ALLOWED_REASON_RESTRICTED_MODE_PERMISSIONS = 1 << 4;
    /**
     * Flag to indicate that app is exempt from certain network restrictions because of it being
     * in the bound top or top procstate.
     *
     * @hide
     */
    public static final int ALLOWED_REASON_TOP = 1 << 5;
    /**
     * Flag to indicate that app is exempt from low power standby restrictions because of it being
     * allowlisted.
     *
     * @hide
     */
    public static final int ALLOWED_REASON_LOW_POWER_STANDBY_ALLOWLIST = 1 << 6;
    /**
     * Flag to indicate that app is exempt from certain metered network restrictions because user
     * explicitly exempted it.
@@ -752,6 +769,14 @@ public class NetworkPolicyManager {
                || (capability & ActivityManager.PROCESS_CAPABILITY_NETWORK) != 0;
    }

    /** @hide */
    public static boolean isProcStateAllowedWhileInLowPowerStandby(@Nullable UidState uidState) {
        if (uidState == null) {
            return false;
        }
        return uidState.procState <= TOP_THRESHOLD_STATE;
    }

    /**
     * Returns true if {@param procState} is considered foreground and as such will be allowed
     * to access network when the device is in data saver mode. Otherwise, false.
+6 −0
Original line number Diff line number Diff line
@@ -91,4 +91,10 @@ public abstract class NetworkPolicyManagerInternal {
     */
    public abstract void setMeteredRestrictedPackagesAsync(
            Set<String> packageNames, int userId);

    /** Informs that Low Power Standby has become active */
    public abstract void setLowPowerStandbyActive(boolean active);

    /** Informs that the Low Power Standby allowlist has changed */
    public abstract void setLowPowerStandbyAllowlist(int[] uids);
}
+196 −7

File changed.

Preview size limit exceeded, changes collapsed.

+8 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;
import com.android.server.net.NetworkPolicyManagerInternal;

import java.io.PrintWriter;
import java.util.Arrays;
@@ -394,7 +395,11 @@ public final class LowPowerStandbyController {
    /** Notify other system components about the updated Low Power Standby active state */
    private void notifyActiveChanged(boolean active) {
        final PowerManagerInternal pmi = LocalServices.getService(PowerManagerInternal.class);
        final NetworkPolicyManagerInternal npmi = LocalServices.getService(
                NetworkPolicyManagerInternal.class);

        pmi.setLowPowerStandbyActive(active);
        npmi.setLowPowerStandbyActive(active);
    }

    @VisibleForTesting
@@ -580,7 +585,10 @@ public final class LowPowerStandbyController {

    private void notifyAllowlistChanged(int[] allowlistUids) {
        final PowerManagerInternal pmi = LocalServices.getService(PowerManagerInternal.class);
        final NetworkPolicyManagerInternal npmi = LocalServices.getService(
                NetworkPolicyManagerInternal.class);
        pmi.setLowPowerStandbyAllowlist(allowlistUids);
        npmi.setLowPowerStandbyAllowlist(allowlistUids);
    }

    private final class LocalService extends LowPowerStandbyControllerInternal {
+93 −44

File changed.

Preview size limit exceeded, changes collapsed.

Loading