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

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

Merge "Show Toasts" into main

parents 011f2a8b 094616cb
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLAS
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.window.flags.Flags.balShowToasts;
import static com.android.server.wm.PendingRemoteAnimationRegistry.TIMEOUT_MS;

import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -459,6 +460,7 @@ public class BackgroundActivityStartController {
                    "With Android 15 BAL hardening this activity start would be blocked"
                            + " (missing opt in by PI creator)! "
                            + state.dump(resultForCaller, resultForRealCaller));
            showBalToast("BAL would be blocked", state);
            // return the realCaller result for backwards compatibility
            return statsLog(resultForRealCaller, state);
        }
@@ -470,6 +472,7 @@ public class BackgroundActivityStartController {
                    "With Android 15 BAL hardening this activity start would be blocked"
                            + " (missing opt in by PI creator)! "
                            + state.dump(resultForCaller, resultForRealCaller));
            showBalToast("BAL would be blocked", state);
            return statsLog(resultForCaller, state);
        }
        if (resultForRealCaller.allows()
@@ -481,6 +484,7 @@ public class BackgroundActivityStartController {
                        "With Android 14 BAL hardening this activity start would be blocked"
                                + " (missing opt in by PI sender)! "
                                + state.dump(resultForCaller, resultForRealCaller));
                showBalToast("BAL would be blocked", state);
                return statsLog(resultForRealCaller, state);
            }
            Slog.wtf(TAG, "Without Android 14 BAL hardening this activity start would be allowed"
@@ -488,6 +492,7 @@ public class BackgroundActivityStartController {
                    + state.dump(resultForCaller, resultForRealCaller));
            // fall through
        }
        showBalToast("BAL blocked", state);
        // anything that has fallen through would currently be aborted
        Slog.w(TAG, "Background activity launch blocked"
                + state.dump(resultForCaller, resultForRealCaller));
@@ -862,8 +867,7 @@ public class BackgroundActivityStartController {
                    + (blockActivityStartAndFeatureEnabled ? " blocked " : " would block ")
                    + getApplicationLabel(mService.mContext.getPackageManager(),
                    launchedFromPackageName);
            UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
                    toastText, Toast.LENGTH_LONG).show());
            showToast(toastText);

            Slog.i(TAG, asmDebugInfo);
        }
@@ -882,6 +886,19 @@ public class BackgroundActivityStartController {
        return true;
    }

    private void showBalToast(String toastText, BalState state) {
        if (balShowToasts()) {
            showToast(toastText
                    + " caller:" + state.mCallingPackage
                    + " realCaller:" + state.mRealCallingPackage);
        }
    }

    private void showToast(String toastText) {
        UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
                toastText, Toast.LENGTH_LONG).show());
    }

    /**
     * If the top activity uid does not match the launching or launched activity, and the launch was
     * not requested from the top uid, we want to clear out all non matching activities to prevent
@@ -930,12 +947,10 @@ public class BackgroundActivityStartController {

        if (ActivitySecurityModelFeatureFlags.shouldShowToast(callingUid)
                && (!shouldBlockActivityStart || finishCount[0] > 0)) {
            UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
                    (shouldBlockActivityStart
            showToast((shouldBlockActivityStart
                    ? "Top activities cleared by "
                    : "Top activities would be cleared by ")
                            + ActivitySecurityModelFeatureFlags.DOC_LINK,
                    Toast.LENGTH_LONG).show());
                    + ActivitySecurityModelFeatureFlags.DOC_LINK);

            Slog.i(TAG, getDebugInfoForActivitySecurity("Clear Top", sourceRecord, targetRecord,
                    targetTask, targetTaskTop, realCallingUid, balCode, shouldBlockActivityStart,
@@ -1013,11 +1028,10 @@ public class BackgroundActivityStartController {
        }

        if (ActivitySecurityModelFeatureFlags.shouldShowToast(callingUid)) {
            UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
                    (ActivitySecurityModelFeatureFlags.DOC_LINK
            showToast((ActivitySecurityModelFeatureFlags.DOC_LINK
                    + (restrictActivitySwitch ? " returned home due to "
                    : " would return home due to ")
                            + callingLabel), Toast.LENGTH_LONG).show());
                    + callingLabel));
        }

        // If the activity switch should be restricted, return home rather than the