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

Commit bb04a086 authored by Achim Thesmann's avatar Achim Thesmann Committed by Android (Google) Code Review
Browse files

Merge "Consider grace period use a violation in BAL strict mode" into main

parents 61b95774 ba99059c
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -75,4 +75,9 @@ flag {
    bug: "362575865"
}

flag {
    name: "bal_strict_mode_grace_period"
    namespace: "responsible_apis"
    description: "Strict mode violation triggered by grace period usage"
    bug: "384807495"
}
+15 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ 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.balStrictModeRo;
import static com.android.window.flags.Flags.balStrictModeGracePeriod;

import static java.lang.annotation.RetentionPolicy.SOURCE;
import static java.util.Objects.requireNonNull;
@@ -1912,7 +1913,14 @@ public class BackgroundActivityStartController {
                            (state.mOriginatingPendingIntent != null));
        }

        logIfOnlyAllowedBy(finalVerdict, state, BAL_ALLOW_GRACE_PERIOD);
        if (logIfOnlyAllowedBy(finalVerdict, state, BAL_ALLOW_GRACE_PERIOD)) {
            if (balStrictModeRo() && balStrictModeGracePeriod()) {
                String abortDebugMessage = "Activity start is only allowed by grace period. "
                        + "This may stop working in the future. "
                        + "intent: " + state.mIntent;
                strictModeLaunchAborted(state.mRealCallingUid, abortDebugMessage);
            }
        }
        logIfOnlyAllowedBy(finalVerdict, state, BAL_ALLOW_NON_APP_VISIBLE_WINDOW);

        if (balImprovedMetrics()) {
@@ -1956,24 +1964,29 @@ public class BackgroundActivityStartController {
     * Logs details about the activity starts if the only reason it is allowed is the provided
     * {@code balCode}.
     */
    private static void logIfOnlyAllowedBy(BalVerdict finalVerdict, BalState state, int balCode) {
    private static boolean logIfOnlyAllowedBy(BalVerdict finalVerdict, BalState state,
            int balCode) {
        if (finalVerdict.getRawCode() == balCode) {
            if (state.realCallerExplicitOptInOrAutoOptIn()
                    && state.mResultForRealCaller != null
                    && state.mResultForRealCaller.allows()
                    && state.mResultForRealCaller.getRawCode() != balCode) {
                // real caller could allow with a different exemption
                return false;
            } else if (state.callerExplicitOptInOrAutoOptIn()
                    && state.mResultForCaller != null
                    && state.mResultForCaller.allows()
                    && state.mResultForCaller.getRawCode() != balCode) {
                // caller could allow with a different exemption
                return false;
            } else {
                // log to determine grace period length distribution
                Slog.wtf(TAG, "Activity start ONLY allowed by " + balCodeToString(balCode) + " "
                        + finalVerdict.mMessage + ": " + state);
                return true;
            }
        }
        return false;
    }

    @VisibleForTesting