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

Commit 8546a444 authored by Felipe Leme's avatar Felipe Leme
Browse files

Removed the POLICY_ALLOW_BACKGROUND_BATTERY_SAVE constant.

That constant was created back in 2014 in the intial Battery Saver
implementation, but it's not used anymore (since the power saving
whitelist is fetched from DeviceIdleController).

Test: m -j32 FrameworksCoreTests &&  adb install -r -g
${ANDROID_PRODUCT_OUT}/data/app/FrameworksCoreTests/FrameworksCoreTests.apk
&& adb shell am instrument -e class
"android.net.NetworkPolicyManagerTest" -w
"com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner"

BUG: 28791717

Change-Id: Ic2c0bcb9736ce8b40e04fd644953e68241d06a69
parent b1e823a8
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -46,8 +46,6 @@ public class NetworkPolicyManager {
    public static final int POLICY_NONE = 0x0;
    /** Reject network usage on metered networks when application in background. */
    public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
    /** Allow network use (metered or not) in the background in battery save mode. */
    public static final int POLICY_ALLOW_BACKGROUND_BATTERY_SAVE = 0x2;

    /*
     * Rules defining whether an uid has access to a network given its type (metered / non-metered).
@@ -126,8 +124,8 @@ public class NetworkPolicyManager {
    /**
     * Set policy flags for specific UID.
     *
     * @param policy {@link #POLICY_NONE} or combination of flags like
     * {@link #POLICY_REJECT_METERED_BACKGROUND} or {@link #POLICY_ALLOW_BACKGROUND_BATTERY_SAVE}.
     * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
     *     although it is not validated.
     */
    public void setUidPolicy(int uid, int policy) {
        try {
@@ -138,9 +136,12 @@ public class NetworkPolicyManager {
    }

    /**
     * Add policy flags for specific UID.  The given policy bits will be set for
     * the uid.  Policy flags may be either
     * {@link #POLICY_REJECT_METERED_BACKGROUND} or {@link #POLICY_ALLOW_BACKGROUND_BATTERY_SAVE}.
     * Add policy flags for specific UID.
     *
     * <p>The given policy bits will be set for the uid.
     *
     * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
     *     although it is not validated.
     */
    public void addUidPolicy(int uid, int policy) {
        try {
@@ -151,9 +152,12 @@ public class NetworkPolicyManager {
    }

    /**
     * Clear/remove policy flags for specific UID.  The given policy bits will be set for
     * the uid.  Policy flags may be either
     * {@link #POLICY_REJECT_METERED_BACKGROUND} or {@link #POLICY_ALLOW_BACKGROUND_BATTERY_SAVE}.
     * Clear/remove policy flags for specific UID.
     *
     * <p>The given policy bits will be set for the uid.
     *
     * @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
     *     although it is not validated.
     */
    public void removeUidPolicy(int uid, int policy) {
        try {
+0 −3
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package android.net;

import static android.net.NetworkPolicyManager.MASK_ALL_NETWORKS;
import static android.net.NetworkPolicyManager.MASK_METERED_NETWORKS;
import static android.net.NetworkPolicyManager.POLICY_ALLOW_BACKGROUND_BATTERY_SAVE;
import static android.net.NetworkPolicyManager.POLICY_NONE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
@@ -79,8 +78,6 @@ public class NetworkPolicyManagerTest {
        uidPoliciesToStringTest(POLICY_NONE, "0 (NONE)");
        uidPoliciesToStringTest(POLICY_REJECT_METERED_BACKGROUND,
                "1 (REJECT_METERED_BACKGROUND)");
        uidPoliciesToStringTest(POLICY_ALLOW_BACKGROUND_BATTERY_SAVE,
                "2 (ALLOW_BACKGROUND_BATTERY_SAVE)");
    }

    private void uidPoliciesToStringTest(int policyRules, String... expectedOptions) {
+5 −4
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.NetworkPolicy.LIMIT_DISABLED;
import static android.net.NetworkPolicy.WARNING_DISABLED;
import static android.net.NetworkPolicyManager.POLICY_ALLOW_BACKGROUND_BATTERY_SAVE;
import static android.net.NetworkPolicyManager.POLICY_NONE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
@@ -297,17 +296,19 @@ public class NetworkPolicyManagerServiceTest {
    @Test
    @NetPolicyXml("restrict-background-lists-whitelist-format.xml")
    public void testRestrictBackgroundLists_whitelistFormat() throws Exception {
        // UIds that are whitelisted
        // UIds that are whitelisted.
        final int[] whitelisted = mService.getRestrictBackgroundWhitelistedUids();
        assertContainsInAnyOrder(whitelisted, UID_A, UID_B, UID_C);
        assertUidPolicy(UID_A, POLICY_NONE);
        assertUidPolicy(UID_B, POLICY_NONE);
        assertUidPolicy(UID_C, POLICY_NONE);

        // UIDs that are blacklisted
        // UIDs that are blacklisted.
        assertUidPolicy(UID_D, POLICY_NONE);
        assertUidPolicy(UID_E, POLICY_REJECT_METERED_BACKGROUND);
        assertUidPolicy(UID_F, POLICY_ALLOW_BACKGROUND_BATTERY_SAVE);

        // UIDS that have legacy policies.
        assertUidPolicy(UID_F, 2);
    }

    // NOTE: testPolicyChangeTriggersListener() and testUidForeground() are too superficial, they