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

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

Merge "Cleanup flag com.android.server.am.restrict_priority_values." into main

parents cbbc2ed8 1b90f87c
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -132,9 +132,6 @@ public final class BroadcastFilter extends IntentFilter {
    @VisibleForTesting
    static int calculateAdjustedPriority(int owningUid, int priority,
            ApplicationInfo applicationInfo, PlatformCompat platformCompat) {
        if (!Flags.restrictPriorityValues()) {
            return priority;
        }
        final long token = Binder.clearCallingIdentity();
        try {
            if (!platformCompat.isChangeEnabledInternalNoLogging(
+0 −8
Original line number Diff line number Diff line
package: "com.android.server.am"
container: "system"

flag {
    name: "restrict_priority_values"
    namespace: "backstage_power"
    description: "Restrict priority values defined by non-system apps"
    is_fixed_read_only: true
    bug: "369487976"
}

flag {
    name: "limit_priority_scope"
    namespace: "backstage_power"
+0 −76
Original line number Diff line number Diff line
@@ -21,15 +21,12 @@ import static android.content.IntentFilter.SYSTEM_LOW_PRIORITY;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import android.content.pm.ApplicationInfo;
import android.os.Process;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.util.Pair;

@@ -62,7 +59,6 @@ public class BroadcastFilterTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES)
    public void testCalculateAdjustedPriority() {
        {
            // Pairs of {initial-priority, expected-adjusted-priority}
@@ -96,7 +92,6 @@ public class BroadcastFilterTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES)
    public void testCalculateAdjustedPriority_withChangeIdDisabled() {
        doReturn(false).when(mPlatformCompat).isChangeEnabledInternalNoLogging(
                eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), any(ApplicationInfo.class));
@@ -132,77 +127,6 @@ public class BroadcastFilterTest {
        }
    }

    @Test
    @DisableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES)
    public void testCalculateAdjustedPriority_withFlagDisabled() {
        {
            // Pairs of {initial-priority, expected-adjusted-priority}
            final Pair<Integer, Integer>[] priorities = new Pair[] {
                    Pair.create(SYSTEM_HIGH_PRIORITY, SYSTEM_HIGH_PRIORITY),
                    Pair.create(SYSTEM_LOW_PRIORITY, SYSTEM_LOW_PRIORITY),
                    Pair.create(SYSTEM_HIGH_PRIORITY + 1, SYSTEM_HIGH_PRIORITY + 1),
                    Pair.create(SYSTEM_LOW_PRIORITY - 1, SYSTEM_LOW_PRIORITY - 1),
                    Pair.create(SYSTEM_HIGH_PRIORITY - 2, SYSTEM_HIGH_PRIORITY - 2),
                    Pair.create(SYSTEM_LOW_PRIORITY + 2, SYSTEM_LOW_PRIORITY + 2)
            };
            for (Pair<Integer, Integer> priorityPair : priorities) {
                assertAdjustedPriorityForSystemUid(priorityPair.first, priorityPair.second);
            }
        }

        {
            // Pairs of {initial-priority, expected-adjusted-priority}
            final Pair<Integer, Integer>[] priorities = new Pair[] {
                    Pair.create(SYSTEM_HIGH_PRIORITY, SYSTEM_HIGH_PRIORITY),
                    Pair.create(SYSTEM_LOW_PRIORITY, SYSTEM_LOW_PRIORITY),
                    Pair.create(SYSTEM_HIGH_PRIORITY + 1, SYSTEM_HIGH_PRIORITY + 1),
                    Pair.create(SYSTEM_LOW_PRIORITY - 1, SYSTEM_LOW_PRIORITY - 1),
                    Pair.create(SYSTEM_HIGH_PRIORITY - 2, SYSTEM_HIGH_PRIORITY - 2),
                    Pair.create(SYSTEM_LOW_PRIORITY + 2, SYSTEM_LOW_PRIORITY + 2)
            };
            for (Pair<Integer, Integer> priorityPair : priorities) {
                assertAdjustedPriorityForAppUid(priorityPair.first, priorityPair.second);
            }
        }
    }

    @Test
    @DisableFlags(Flags.FLAG_RESTRICT_PRIORITY_VALUES)
    public void testCalculateAdjustedPriority_withFlagDisabled_withChangeIdDisabled() {
        doReturn(false).when(mPlatformCompat).isChangeEnabledByUidInternalNoLogging(
                eq(BroadcastFilter.RESTRICT_PRIORITY_VALUES), anyInt());

        {
            // Pairs of {initial-priority, expected-adjusted-priority}
            final Pair<Integer, Integer>[] priorities = new Pair[] {
                    Pair.create(SYSTEM_HIGH_PRIORITY, SYSTEM_HIGH_PRIORITY),
                    Pair.create(SYSTEM_LOW_PRIORITY, SYSTEM_LOW_PRIORITY),
                    Pair.create(SYSTEM_HIGH_PRIORITY + 1, SYSTEM_HIGH_PRIORITY + 1),
                    Pair.create(SYSTEM_LOW_PRIORITY - 1, SYSTEM_LOW_PRIORITY - 1),
                    Pair.create(SYSTEM_HIGH_PRIORITY - 2, SYSTEM_HIGH_PRIORITY - 2),
                    Pair.create(SYSTEM_LOW_PRIORITY + 2, SYSTEM_LOW_PRIORITY + 2)
            };
            for (Pair<Integer, Integer> priorityPair : priorities) {
                assertAdjustedPriorityForSystemUid(priorityPair.first, priorityPair.second);
            }
        }

        {
            // Pairs of {initial-priority, expected-adjusted-priority}
            final Pair<Integer, Integer>[] priorities = new Pair[] {
                    Pair.create(SYSTEM_HIGH_PRIORITY, SYSTEM_HIGH_PRIORITY),
                    Pair.create(SYSTEM_LOW_PRIORITY, SYSTEM_LOW_PRIORITY),
                    Pair.create(SYSTEM_HIGH_PRIORITY + 1, SYSTEM_HIGH_PRIORITY + 1),
                    Pair.create(SYSTEM_LOW_PRIORITY - 1, SYSTEM_LOW_PRIORITY - 1),
                    Pair.create(SYSTEM_HIGH_PRIORITY - 2, SYSTEM_HIGH_PRIORITY - 2),
                    Pair.create(SYSTEM_LOW_PRIORITY + 2, SYSTEM_LOW_PRIORITY + 2)
            };
            for (Pair<Integer, Integer> priorityPair : priorities) {
                assertAdjustedPriorityForAppUid(priorityPair.first, priorityPair.second);
            }
        }
    }

    private void assertAdjustedPriorityForSystemUid(int priority, int expectedAdjustedPriority) {
        assertAdjustedPriority(Process.SYSTEM_UID, priority, expectedAdjustedPriority);
    }