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

Commit 89f6d9c0 authored by Achim Thesmann's avatar Achim Thesmann
Browse files

Remove bal_improved_metrics

Test: atest BackgroundActivityStartControllerExemptionTests BackgroundActivityStartControllerTests BackgroundActivityStartControllerLogTests BackgroundActivityLaunchTest BackgroundLaunchProcessControllerTests
Bug: 409611524
Flag: EXEMPT flag removal
Change-Id: I7ddcc6fd419d7a7ef348b0cbb881829a195edb5f
parent 81630075
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -36,13 +36,6 @@ flag {
    bug: "283801068"
}

flag {
    name: "bal_improved_metrics"
    namespace: "responsible_apis"
    description: "Improved metrics."
    bug: "339245692"
}

flag {
    name: "bal_additional_start_modes"
    namespace: "responsible_apis"
+10 −32
Original line number Diff line number Diff line
@@ -44,14 +44,13 @@ import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_FG_ONLY;
import static com.android.server.wm.ActivityTaskSupervisor.getApplicationLabel;
import static com.android.server.wm.PendingRemoteAnimationRegistry.TIMEOUT_MS;
import static com.android.window.flags.Flags.balAdditionalLogging;
import static com.android.window.flags.Flags.balAdditionalStartModes;
import static com.android.window.flags.Flags.balDontBringExistingBackgroundTaskStackToFg;
import static com.android.window.flags.Flags.balImprovedMetrics;
import static com.android.window.flags.Flags.balRequireOptInByPendingIntentCreator;
import static com.android.window.flags.Flags.balShowToastsBlocked;
import static com.android.window.flags.Flags.balStrictModeGracePeriod;
import static com.android.window.flags.Flags.balStrictModeRo;
import static com.android.window.flags.Flags.balAdditionalLogging;

import static java.lang.annotation.RetentionPolicy.SOURCE;
import static java.util.Objects.requireNonNull;
@@ -1942,7 +1941,6 @@ public class BackgroundActivityStartController {
        logIfOnlyAllowedBy(finalVerdict, state, BAL_ALLOW_NON_APP_VISIBLE_WINDOW);
        logIfOnlyAllowedBy(finalVerdict, state, BAL_ALLOW_TOKEN);

        if (balImprovedMetrics()) {
        if (shouldLogStats(finalVerdict, state)) {
            String activityName;
            if (shouldLogIntentActivity(finalVerdict, state)) {
@@ -1956,26 +1954,6 @@ public class BackgroundActivityStartController {
        } else {
            writeBalAllowedLogMinimal(state);
        }
        } else {
            @BalCode int code = finalVerdict.getCode();
            int callingUid = state.mCallingUid;
            int realCallingUid = state.mRealCallingUid;
            Intent intent = state.mIntent;

            if (code == BAL_ALLOW_PENDING_INTENT
                    && (callingUid < Process.FIRST_APPLICATION_UID
                    || realCallingUid < Process.FIRST_APPLICATION_UID)) {
                String activityName = intent != null
                        ? requireNonNull(intent.getComponent()).flattenToShortString() : "";
                writeBalAllowedLog(activityName, BAL_ALLOW_PENDING_INTENT,
                        state);
            }
            if (code == BAL_ALLOW_PERMISSION || code == BAL_ALLOW_FOREGROUND
                    || code == BAL_ALLOW_SAW_PERMISSION) {
                // We don't need to know which activity in this case.
                writeBalAllowedLog("", code, state);
            }
        }
        return finalVerdict;
    }

+1 −8
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_GRACE_PERIOD;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_PERMISSION;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_TOKEN;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_VISIBLE_WINDOW;
import static com.android.window.flags.Flags.balImprovedMetrics;

import static java.util.Objects.requireNonNull;

@@ -133,9 +131,6 @@ class BackgroundLaunchProcessController {
            BalVerdict tokenVerdict = isBackgroundStartAllowedByToken(uid,
                    packageName, checkConfiguration.isCheckingForFgsStart);
            if (tokenVerdict.allows()) {
                if (!balImprovedMetrics()) {
                    return new BalVerdict(BAL_ALLOW_PERMISSION, tokenVerdict.toString());
                }
                return tokenVerdict;
            }
        }
@@ -143,9 +138,7 @@ class BackgroundLaunchProcessController {
        // But still respect the appSwitchState.
        if (checkConfiguration.checkVisibility && appSwitchState != APP_SWITCH_DISALLOW
                && isBoundByForegroundUid()) {
            return new BalVerdict(balImprovedMetrics() ? BAL_ALLOW_BOUND_BY_FOREGROUND
                    : BAL_ALLOW_VISIBLE_WINDOW, /*background*/
                    "process bound by foreground uid");
            return new BalVerdict(BAL_ALLOW_BOUND_BY_FOREGROUND, "process bound by foreground uid");
        }
        // Allow if the caller has an activity in any foreground task.
        if (checkConfiguration.checkOtherExemptions && hasActivityInVisibleTask
+12 −38
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_PERMISSION;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_VISIBLE_WINDOW;
import static com.android.server.wm.BackgroundActivityStartController.BAL_BLOCK;
import static com.android.window.flags.Flags.balImprovedMetrics;

import static com.google.common.truth.Truth.assertThat;

@@ -259,12 +258,8 @@ public class BackgroundActivityStartControllerTests {

        // assertions
        assertThat(verdict.getCode()).isEqualTo(BackgroundActivityStartController.BAL_BLOCK);
        if (balImprovedMetrics()) {
        assertThat(mBalAllowedLogs).containsExactly(
                new BalAllowedLog("package.app3/someClass", BAL_BLOCK));
        } else {
            assertThat(mBalAllowedLogs).isEmpty(); // not allowed
        }
    }

    // Tests for BackgroundActivityStartController.checkBackgroundActivityStart
@@ -294,12 +289,8 @@ public class BackgroundActivityStartControllerTests {

        // assertions
        assertThat(verdict).isEqualTo(BalVerdict.BLOCK);
        if (balImprovedMetrics()) {
        assertThat(mBalAllowedLogs).containsExactly(
                new BalAllowedLog("package.app3/someClass", BAL_BLOCK));
        } else {
            assertThat(mBalAllowedLogs).isEmpty(); // not allowed
        }
    }

    @Test
@@ -329,12 +320,8 @@ public class BackgroundActivityStartControllerTests {

        // assertions
        assertThat(verdict).isEqualTo(callerVerdict);
        if (balImprovedMetrics()) {
        assertThat(mBalAllowedLogs).containsExactly(
                new BalAllowedLog("package.app3/someClass", callerVerdict.getCode()));
        } else {
            assertThat(mBalAllowedLogs).isEmpty(); // non-critical exception
        }
    }

    @Test
@@ -398,13 +385,8 @@ public class BackgroundActivityStartControllerTests {

        // assertions
        assertThat(verdict).isEqualTo(callerVerdict);
        if (balImprovedMetrics()) {
        assertThat(mBalAllowedLogs).containsExactly(
                new BalAllowedLog("package.app3/someClass", callerVerdict.getCode()));
        } else {
            assertThat(mBalAllowedLogs).containsExactly(
                    new BalAllowedLog("", callerVerdict.getCode()));
        }
    }

    @Test
@@ -440,12 +422,8 @@ public class BackgroundActivityStartControllerTests {

        // assertions
        assertThat(verdict).isEqualTo(BalVerdict.BLOCK);
        if (balImprovedMetrics()) {
        assertThat(mBalAllowedLogs).containsExactly(
                new BalAllowedLog("package.app3/someClass", BAL_BLOCK));
        } else {
            assertThat(mBalAllowedLogs).isEmpty();
        }
    }

    @Test
@@ -477,12 +455,8 @@ public class BackgroundActivityStartControllerTests {

        // assertions
        assertThat(verdict).isEqualTo(callerVerdict);
        if (balImprovedMetrics()) {
        assertThat(mBalAllowedLogs).containsExactly(
                new BalAllowedLog("package.app3/someClass", callerVerdict.getCode()));
        } else {
            assertThat(mBalAllowedLogs).isEmpty();
        }
    }

    @Test
+0 −56
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_GRACE_PERIOD;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_PERMISSION;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_TOKEN;
import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_VISIBLE_WINDOW;
import static com.android.server.wm.BackgroundActivityStartController.BAL_BLOCK;

import static com.google.common.truth.Truth.assertThat;
@@ -33,15 +32,12 @@ import android.app.BackgroundStartPrivileges;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.filters.SmallTest;

import com.android.server.wm.BackgroundActivityStartController.BalVerdict;
import com.android.window.flags.Flags;

import org.junit.ClassRule;
import org.junit.Rule;
@@ -132,25 +128,6 @@ public class BackgroundLaunchProcessControllerTests {
    }

    @Test
    @DisableFlags(Flags.FLAG_BAL_IMPROVED_METRICS)
    public void testAllowedByTokenNoCallbackOld() {
        mController = new BackgroundLaunchProcessController(mHasActiveVisibleWindow::contains,
                null);
        Binder token = new Binder();
        mActivityStartAllowed.add(token);
        mController.addOrUpdateAllowBackgroundStartPrivileges(token,
                BackgroundStartPrivileges.ALLOW_BAL);
        BalVerdict balVerdict = mController.areBackgroundActivityStartsAllowed(
                mPid, mUid, mPackageName,
                mAppSwitchState, mBalCheckConfiguration,
                mHasActivityInVisibleTask, mHasBackgroundActivityStartPrivileges,
                mLastStopAppSwitchesTime, mLastActivityLaunchTime,
                mLastActivityFinishTime);
        assertThat(balVerdict.getCode()).isEqualTo(BAL_ALLOW_PERMISSION);
    }

    @Test
    @EnableFlags(Flags.FLAG_BAL_IMPROVED_METRICS)
    public void testAllowedByTokenNoCallback() {
        mController = new BackgroundLaunchProcessController(mHasActiveVisibleWindow::contains,
                null);
@@ -168,23 +145,6 @@ public class BackgroundLaunchProcessControllerTests {
    }

    @Test
    @DisableFlags(Flags.FLAG_BAL_IMPROVED_METRICS)
    public void testAllowedByTokenOld() {
        Binder token = new Binder();
        mActivityStartAllowed.add(token);
        mController.addOrUpdateAllowBackgroundStartPrivileges(token,
                BackgroundStartPrivileges.ALLOW_BAL);
        BalVerdict balVerdict = mController.areBackgroundActivityStartsAllowed(
                mPid, mUid, mPackageName,
                mAppSwitchState, mBalCheckConfiguration,
                mHasActivityInVisibleTask, mHasBackgroundActivityStartPrivileges,
                mLastStopAppSwitchesTime, mLastActivityLaunchTime,
                mLastActivityFinishTime);
        assertThat(balVerdict.getCode()).isEqualTo(BAL_ALLOW_PERMISSION);
    }

    @Test
    @EnableFlags(Flags.FLAG_BAL_IMPROVED_METRICS)
    public void testAllowedByToken() {
        Binder token = new Binder();
        mActivityStartAllowed.add(token);
@@ -200,22 +160,6 @@ public class BackgroundLaunchProcessControllerTests {
    }

    @Test
    @DisableFlags(Flags.FLAG_BAL_IMPROVED_METRICS)
    public void testBoundByForegroundOld() {
        mAppSwitchState = APP_SWITCH_ALLOW;
        mController.addBoundClientUid(999, "visible.package", Context.BIND_ALLOW_ACTIVITY_STARTS);
        mHasActiveVisibleWindow.add(999);
        BalVerdict balVerdict = mController.areBackgroundActivityStartsAllowed(
                mPid, mUid, mPackageName,
                mAppSwitchState, mBalCheckConfiguration,
                mHasActivityInVisibleTask, mHasBackgroundActivityStartPrivileges,
                mLastStopAppSwitchesTime, mLastActivityLaunchTime,
                mLastActivityFinishTime);
        assertThat(balVerdict.getCode()).isEqualTo(BAL_ALLOW_VISIBLE_WINDOW);
    }

    @Test
    @EnableFlags(Flags.FLAG_BAL_IMPROVED_METRICS)
    public void testBoundByForeground() {
        mAppSwitchState = APP_SWITCH_ALLOW;
        mController.addBoundClientUid(999, "visible.package", Context.BIND_ALLOW_ACTIVITY_STARTS);