Revert "Create a Strict Mode violation for Background Activity L..."

Revert submission 25832108-BAL_StrictMode

Reason for revert: Reading flag before DeviceConfig is ready

Bug: 376375422
Reverted changes: /q/submissionid:25832108-BAL_StrictMode

Change-Id: I86928e415a0a63bae40dfad96c739119baf35f7a
diff --git a/core/api/current.txt b/core/api/current.txt
index 8342f25..46a864e 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -34124,7 +34124,6 @@
     method public android.os.StrictMode.VmPolicy build();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectActivityLeaks();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectAll();
-    method @FlaggedApi("com.android.window.flags.bal_strict_mode") @NonNull public android.os.StrictMode.VmPolicy.Builder detectBlockedBackgroundActivityLaunch();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectCleartextNetwork();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectContentUriWithoutPermission();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectCredentialProtectedWhileLocked();
@@ -34137,7 +34136,6 @@
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectNonSdkApiUsage();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectUnsafeIntentLaunch();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder detectUntaggedSockets();
-    method @FlaggedApi("com.android.window.flags.bal_strict_mode") @NonNull public android.os.StrictMode.VmPolicy.Builder ignoreBlockedBackgroundActivityLaunch();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder penaltyDeath();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder penaltyDeathOnCleartextNetwork();
     method @NonNull public android.os.StrictMode.VmPolicy.Builder penaltyDeathOnFileUriExposure();
diff --git a/core/java/android/app/IActivityTaskManager.aidl b/core/java/android/app/IActivityTaskManager.aidl
index 003104a..0a05144 100644
--- a/core/java/android/app/IActivityTaskManager.aidl
+++ b/core/java/android/app/IActivityTaskManager.aidl
@@ -359,23 +359,6 @@
             in RemoteCallback navigationObserver, in BackAnimationAdapter adaptor);
 
     /**
-     * registers a callback to be invoked when a background activity launch is aborted.
-     *
-     * @param observer callback to be registered.
-     * @return true if the callback was successfully registered, false otherwise.
-     * @hide
-     */
-    boolean registerBackgroundActivityStartCallback(in IBinder binder);
-
-    /**
-     * unregisters a callback to be invoked when a background activity launch is aborted.
-     *
-     * @param observer callback to be registered.
-     * @hide
-     */
-    void unregisterBackgroundActivityStartCallback(in IBinder binder);
-
-    /**
      * registers a callback to be invoked when the screen is captured.
      *
      * @param observer callback to be registered.
diff --git a/core/java/android/app/IBackgroundActivityLaunchCallback.aidl b/core/java/android/app/IBackgroundActivityLaunchCallback.aidl
deleted file mode 100644
index 6dfb518..0000000
--- a/core/java/android/app/IBackgroundActivityLaunchCallback.aidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-* Copyright 2024, The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package android.app;
-
-/**
- * Callback to find out when a background activity launch is aborted.
- * @hide
- */
-oneway interface IBackgroundActivityLaunchCallback
-{
-    void onBackgroundActivityLaunchAborted(in String message);
-}
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 60a9e05..81dc46e 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -20,22 +20,17 @@
 import static com.android.internal.util.FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__EXPLICIT_INTENT_FILTER_UNMATCH;
 import static com.android.internal.util.FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__INTERNAL_NON_EXPORTED_COMPONENT_MATCH;
 import static com.android.internal.util.FrameworkStatsLog.UNSAFE_INTENT_EVENT_REPORTED__EVENT_TYPE__NULL_ACTION_MATCH;
-import static com.android.window.flags.Flags.balStrictMode;
 
 import android.animation.ValueAnimator;
-import android.annotation.FlaggedApi;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
 import android.annotation.TestApi;
 import android.app.ActivityManager;
-import android.app.ActivityTaskManager;
 import android.app.ActivityThread;
 import android.app.IActivityManager;
-import android.app.IBackgroundActivityLaunchCallback;
 import android.app.IUnsafeIntentStrictModeCallback;
-import android.app.PendingIntent;
 import android.app.compat.CompatChanges;
 import android.compat.annotation.ChangeId;
 import android.compat.annotation.EnabledSince;
@@ -50,7 +45,6 @@
 import android.net.TrafficStats;
 import android.net.Uri;
 import android.os.storage.IStorageManager;
-import android.os.strictmode.BackgroundActivityLaunchViolation;
 import android.os.strictmode.CleartextNetworkViolation;
 import android.os.strictmode.ContentUriWithoutPermissionViolation;
 import android.os.strictmode.CredentialProtectedWhileLockedViolation;
@@ -88,7 +82,6 @@
 import com.android.internal.util.FastPrintWriter;
 import com.android.internal.util.HexDump;
 import com.android.internal.util.Preconditions;
-import com.android.window.flags.Flags;
 
 import dalvik.system.BlockGuard;
 import dalvik.system.CloseGuard;
@@ -273,7 +266,6 @@
             DETECT_VM_IMPLICIT_DIRECT_BOOT,
             DETECT_VM_INCORRECT_CONTEXT_USE,
             DETECT_VM_UNSAFE_INTENT_LAUNCH,
-            DETECT_VM_BACKGROUND_ACTIVITY_LAUNCH_ABORTED,
             PENALTY_GATHER,
             PENALTY_LOG,
             PENALTY_DIALOG,
@@ -317,8 +309,6 @@
     private static final int DETECT_VM_INCORRECT_CONTEXT_USE = 1 << 12;
     /** @hide */
     private static final int DETECT_VM_UNSAFE_INTENT_LAUNCH = 1 << 13;
-    /** @hide */
-    private static final int DETECT_VM_BACKGROUND_ACTIVITY_LAUNCH_ABORTED = 1 << 14;
 
     /** @hide */
     private static final int DETECT_VM_ALL = 0x0000ffff;
@@ -912,9 +902,6 @@
                 if (targetSdk >= Build.VERSION_CODES.S) {
                     detectUnsafeIntentLaunch();
                 }
-                if (balStrictMode() && targetSdk > Build.VERSION_CODES.VANILLA_ICE_CREAM) {
-                    detectBlockedBackgroundActivityLaunch();
-                }
 
                 // TODO: Decide whether to detect non SDK API usage beyond a certain API level.
                 // TODO: enable detectImplicitDirectBoot() once system is less noisy
@@ -1153,39 +1140,6 @@
             }
 
             /**
-             * Detects when your app is blocked from launching a background activity or a
-             * PendingIntent created by your app cannot be launched.
-             * <p>
-             * Starting an activity requires <a
-             * href="https://developer.android.com/guide/components/activities/background-starts
-             * ">specific permissions</a> which may depend on the state at runtime and especially
-             * in case of {@link android.app.PendingIntent} starts on the collaborating app.
-             * If the activity start is blocked methods like {@link Context#startActivity(Intent)}
-             * or {@link PendingIntent#send()} have no way to return that information. Instead you
-             * can use this strct mode feature to detect blocked starts.
-             * <p>
-             * Note that in some cases blocked starts may be unavoidable, e.g. when the user clicks
-             * the home button while the app tries to start a new activity.
-             */
-            @SuppressWarnings("BuilderSetStyle")
-            @FlaggedApi(Flags.FLAG_BAL_STRICT_MODE)
-            public @NonNull Builder detectBlockedBackgroundActivityLaunch() {
-                return enable(DETECT_VM_BACKGROUND_ACTIVITY_LAUNCH_ABORTED);
-            }
-
-            /**
-             * Stops detecting whether your app is blocked from launching a background activity or
-             * a PendingIntent created by your app cannot be launched.
-             * <p>
-             * This disables the effect of {@link #detectBlockedBackgroundActivityLaunch()}.
-             */
-            @SuppressWarnings("BuilderSetStyle")
-            @FlaggedApi(Flags.FLAG_BAL_STRICT_MODE)
-            public @NonNull Builder ignoreBlockedBackgroundActivityLaunch() {
-                return disable(DETECT_VM_BACKGROUND_ACTIVITY_LAUNCH_ABORTED);
-            }
-
-            /**
              * Crashes the whole process on violation. This penalty runs at the end of all enabled
              * penalties so you'll still get your logging or other violations before the process
              * dies.
@@ -2179,25 +2133,10 @@
                 registerIntentMatchingRestrictionCallback();
             }
 
-            if ((sVmPolicy.mask & DETECT_VM_BACKGROUND_ACTIVITY_LAUNCH_ABORTED) != 0) {
-                registerBackgroundActivityLaunchCallback();
-            }
-
             setBlockGuardVmPolicy(sVmPolicy.mask);
         }
     }
 
-    private static void registerBackgroundActivityLaunchCallback() {
-        try {
-            ActivityTaskManager.getService().registerBackgroundActivityStartCallback(
-                    new BackgroundActivityLaunchCallback());
-        } catch (DeadObjectException e) {
-            // ignore
-        } catch (RemoteException e) {
-            Log.e(TAG, "RemoteException handling StrictMode violation", e);
-        }
-    }
-
     private static final class UnsafeIntentStrictModeCallback
             extends IUnsafeIntentStrictModeCallback.Stub {
         @Override
@@ -2222,16 +2161,6 @@
         }
     }
 
-    private static final class BackgroundActivityLaunchCallback
-            extends IBackgroundActivityLaunchCallback.Stub {
-        @Override
-        public void onBackgroundActivityLaunchAborted(String message) {
-            if (StrictMode.vmBackgroundActivityLaunchEnabled()) {
-                StrictMode.onBackgroundActivityLaunchAborted(message);
-            }
-        }
-    }
-
     /** Gets the current VM policy. */
     public static VmPolicy getVmPolicy() {
         synchronized (StrictMode.class) {
@@ -2307,11 +2236,6 @@
     }
 
     /** @hide */
-    public static boolean vmBackgroundActivityLaunchEnabled() {
-        return (sVmPolicy.mask & DETECT_VM_BACKGROUND_ACTIVITY_LAUNCH_ABORTED) != 0;
-    }
-
-    /** @hide */
     public static void onSqliteObjectLeaked(String message, Throwable originStack) {
         onVmPolicyViolation(new SqliteObjectLeakedViolation(message, originStack));
     }
@@ -2478,11 +2402,6 @@
         onVmPolicyViolation(new UnsafeIntentLaunchViolation(intent, msg + intent));
     }
 
-    /** @hide */
-    public static void onBackgroundActivityLaunchAborted(String message) {
-        onVmPolicyViolation(new BackgroundActivityLaunchViolation(message));
-    }
-
     /** Assume locked until we hear otherwise */
     private static volatile boolean sCeStorageUnlocked = false;
 
diff --git a/core/java/android/os/strictmode/BackgroundActivityLaunchViolation.java b/core/java/android/os/strictmode/BackgroundActivityLaunchViolation.java
deleted file mode 100644
index aef52c6..0000000
--- a/core/java/android/os/strictmode/BackgroundActivityLaunchViolation.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.os.strictmode;
-
-import android.annotation.NonNull;
-import android.app.Activity;
-
-/**
- * Violation raised when your app is blocked from launching an {@link Activity}
- * (from the background).
- * <p>
- * This occurs when the app:
- * <ul>
- *     <li>Does not have sufficient privileges to launch the Activity.</li>
- *     <li>Has not explicitly opted-in to launch the Activity.</li>
- * </ul>
- * Violations may affect the functionality of your app and should be addressed to ensure
- * proper behavior.
- * @hide
- */
-public class BackgroundActivityLaunchViolation extends Violation {
-
-    /** @hide */
-    public BackgroundActivityLaunchViolation(@NonNull String message) {
-        super(message);
-    }
-}
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 8d4f139..96cb2f2 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -5881,29 +5881,6 @@
     }
 
     /**
-     * Registers an app that uses the Strict Mode for detecting BAL.
-     *
-     * @param callback the callback to register
-     * @return {@code true} if the callback was registered successfully.
-     */
-    @Override
-    public boolean registerBackgroundActivityStartCallback(IBinder callback) {
-        return mTaskSupervisor.getBackgroundActivityLaunchController()
-                .addStrictModeCallback(Binder.getCallingUid(), callback);
-    }
-
-    /**
-     * Unregisters an app that uses the Strict Mode for detecting BAL.
-     *
-     * @param callback the callback to unregister
-     */
-    @Override
-    public void unregisterBackgroundActivityStartCallback(IBinder callback) {
-        mTaskSupervisor.getBackgroundActivityLaunchController()
-                .removeStrictModeCallback(Binder.getCallingUid(), callback);
-    }
-
-    /**
      * Wrap the {@link ActivityOptions} in {@link SafeActivityOptions} and attach caller options
      * that allow using the callers permissions to start background activities.
      */
diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
index e55a169..3e553ad 100644
--- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
+++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
@@ -52,7 +52,6 @@
 import static com.android.window.flags.Flags.balRequireOptInSameUid;
 import static com.android.window.flags.Flags.balRespectAppSwitchStateWhenCheckBoundByForegroundUid;
 import static com.android.window.flags.Flags.balShowToastsBlocked;
-import static com.android.window.flags.Flags.balStrictMode;
 
 import static java.lang.annotation.RetentionPolicy.SOURCE;
 import static java.util.Objects.requireNonNull;
@@ -64,7 +63,6 @@
 import android.app.ActivityOptions;
 import android.app.AppOpsManager;
 import android.app.BackgroundStartPrivileges;
-import android.app.IBackgroundActivityLaunchCallback;
 import android.app.compat.CompatChanges;
 import android.compat.annotation.ChangeId;
 import android.compat.annotation.EnabledAfter;
@@ -73,17 +71,13 @@
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
-import android.os.IBinder;
 import android.os.Process;
-import android.os.RemoteException;
 import android.os.SystemClock;
 import android.os.UserHandle;
 import android.provider.DeviceConfig;
-import android.util.ArrayMap;
 import android.util.ArraySet;
 import android.util.DebugUtils;
 import android.util.Slog;
-import android.util.SparseArray;
 import android.widget.Toast;
 
 import com.android.internal.R;
@@ -98,7 +92,6 @@
 import java.lang.annotation.Retention;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Map;
 import java.util.StringJoiner;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -150,10 +143,6 @@
     private final ActivityTaskManagerService mService;
 
     private final ActivityTaskSupervisor mSupervisor;
-    @GuardedBy("mStrictModeBalCallbacks")
-    private final SparseArray<ArrayMap<IBinder, IBackgroundActivityLaunchCallback>>
-            mStrictModeBalCallbacks = new SparseArray<>();
-
 
     // TODO(b/263368846) Rename when ASM logic is moved in
     @Retention(SOURCE)
@@ -852,120 +841,7 @@
             // only show a toast if either caller or real caller could launch if they opted in
             showToast("BAL blocked. goo.gle/android-bal");
         }
-        BalVerdict verdict = statsLog(BalVerdict.BLOCK, state);
-        if (balStrictMode()) {
-            String abortDebugMessage;
-            if (state.isPendingIntent()) {
-                abortDebugMessage =
-                        "PendingIntent Activity start blocked in " + state.mRealCallingPackage
-                                + ". "
-                                + "PendingIntent was created in " + state.mCallingPackage
-                                + ". "
-                                + (state.mResultForRealCaller.allows()
-                                ? state.mRealCallingPackage
-                                + " could opt in to grant BAL privileges when sending. "
-                                : "")
-                                + (state.mResultForCaller.allows()
-                                ? state.mCallingPackage
-                                + " could opt in to grant BAL privileges when creating."
-                                : "")
-                                + "The intent would have started " + state.mIntent.getComponent();
-            } else {
-                abortDebugMessage = "Activity start blocked. "
-                        + "The intent would have started " + state.mIntent.getComponent();
-            }
-            strictModeLaunchAborted(state.mCallingUid, abortDebugMessage);
-            if (!state.callerIsRealCaller()) {
-                strictModeLaunchAborted(state.mRealCallingUid, abortDebugMessage);
-            }
-        }
-        return verdict;
-    }
-
-    /**
-     * Retrieve a registered strict mode callback for BAL.
-     * @param uid the uid of the app.
-     * @return the callback if it exists, returns <code>null</code> otherwise.
-     */
-    @Nullable
-    Map<IBinder, IBackgroundActivityLaunchCallback> getStrictModeBalCallbacks(int uid) {
-        ArrayMap<IBinder, IBackgroundActivityLaunchCallback> callbackMap;
-        synchronized (mStrictModeBalCallbacks) {
-            callbackMap =
-                    mStrictModeBalCallbacks.get(uid);
-            if (callbackMap == null) {
-                return null;
-            }
-            return new ArrayMap<>(callbackMap);
-        }
-    }
-
-    /**
-     * Add strict mode callback for BAL.
-     *
-     * @param uid      the UID for which the binder is registered.
-     * @param callback the {@link IBackgroundActivityLaunchCallback} binder to call when BAL is
-     *                 blocked.
-     * @return {@code true} if the callback has been successfully added.
-     */
-    boolean addStrictModeCallback(int uid, IBinder callback) {
-        IBackgroundActivityLaunchCallback balCallback =
-                IBackgroundActivityLaunchCallback.Stub.asInterface(callback);
-        synchronized (mStrictModeBalCallbacks) {
-            ArrayMap<IBinder, IBackgroundActivityLaunchCallback> callbackMap =
-                    mStrictModeBalCallbacks.get(uid);
-            if (callbackMap == null) {
-                callbackMap = new ArrayMap<>();
-                mStrictModeBalCallbacks.put(uid, callbackMap);
-            }
-            if (callbackMap.containsKey(callback)) {
-                return false;
-            }
-            callbackMap.put(callback, balCallback);
-        }
-        try {
-            callback.linkToDeath(() -> removeStrictModeCallback(uid, callback), 0);
-        } catch (RemoteException e) {
-            removeStrictModeCallback(uid, callback);
-        }
-        return true;
-    }
-
-    /**
-     * Remove strict mode callback for BAL.
-     *
-     * @param uid      the UID for which the binder is registered.
-     * @param callback the {@link IBackgroundActivityLaunchCallback} binder to call when BAL is
-     *                 blocked.
-     */
-    void removeStrictModeCallback(int uid, IBinder callback) {
-        synchronized (mStrictModeBalCallbacks) {
-            Map<IBinder, IBackgroundActivityLaunchCallback> callbackMap =
-                    mStrictModeBalCallbacks.get(uid);
-            if (callback == null || !callbackMap.containsKey(callback)) {
-                return;
-            }
-            callbackMap.remove(callback);
-            if (callbackMap.isEmpty()) {
-                mStrictModeBalCallbacks.remove(uid);
-            }
-        }
-    }
-
-    private void strictModeLaunchAborted(int callingUid, String message) {
-        Map<IBinder, IBackgroundActivityLaunchCallback> strictModeBalCallbacks =
-                getStrictModeBalCallbacks(callingUid);
-        if (strictModeBalCallbacks == null) {
-            return;
-        }
-        for (Map.Entry<IBinder, IBackgroundActivityLaunchCallback> callbackEntry :
-                strictModeBalCallbacks.entrySet()) {
-            try {
-                callbackEntry.getValue().onBackgroundActivityLaunchAborted(message);
-            } catch (RemoteException e) {
-                removeStrictModeCallback(callingUid, callbackEntry.getKey());
-            }
-        }
+        return statsLog(BalVerdict.BLOCK, state);
     }
 
     /**