Remove BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS

We ended up defaulting to this behavior, so we no longer need this flag.

Bug: 189235490
Bug: 188057823
Test: Build
Change-Id: I62e383978d9b168657f2eac2e6bf4337a91b909b
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index fc676cf..886cd7f 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -400,10 +400,7 @@
     public static final int BIND_BYPASS_POWER_NETWORK_RESTRICTIONS = 0x00020000;
 
     /**
-     * Flag for {@link #bindService}: allow background foreground service starts from the bound
-     * service's process.
-     * This flag is only respected if the caller is holding
-     * {@link android.Manifest.permission#START_FOREGROUND_SERVICES_FROM_BACKGROUND}.
+     * Do not use. This flag is no longer needed nor used.
      * @hide
      */
     @SystemApi
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 562f8f44..bd7d0b3 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -2569,10 +2569,6 @@
                 s.setAllowedBgActivityStartsByBinding(true);
             }
 
-            if ((flags & Context.BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND) != 0) {
-                s.setAllowedBgFgsStartsByBinding(true);
-            }
-
             if ((flags & Context.BIND_NOT_APP_COMPONENT_USAGE) != 0) {
                 s.isNotAppComponentUsage = true;
             }
@@ -4129,9 +4125,6 @@
             if ((c.flags & Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS) != 0) {
                 s.updateIsAllowedBgActivityStartsByBinding();
             }
-            if ((c.flags & Context.BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND) != 0) {
-                s.updateIsAllowedBgFgsStartsByBinding();
-            }
             if (s.app != null) {
                 updateServiceClientActivitiesLocked(s.app.mServices, c, true);
             }
@@ -5856,8 +5849,6 @@
                     final ProcessStateRecord state = app.mState;
                     if (state.isAllowedStartFgsState()) {
                         return getReasonCodeFromProcState(state.getAllowStartFgsState());
-                    } else if (state.areBackgroundFgsStartsAllowedByToken()) {
-                        return REASON_FGS_BINDING;
                     } else {
                         final ActiveInstrumentation instr = app.getActiveInstrumentation();
                         if (instr != null
diff --git a/services/core/java/com/android/server/am/ProcessStateRecord.java b/services/core/java/com/android/server/am/ProcessStateRecord.java
index d83e13c..1fb5572 100644
--- a/services/core/java/com/android/server/am/ProcessStateRecord.java
+++ b/services/core/java/com/android/server/am/ProcessStateRecord.java
@@ -26,7 +26,6 @@
 import android.annotation.ElapsedRealtimeLong;
 import android.app.ActivityManager;
 import android.content.ComponentName;
-import android.os.Binder;
 import android.os.SystemClock;
 import android.util.ArraySet;
 import android.util.Slog;
@@ -302,9 +301,6 @@
     @GuardedBy("mService")
     private int mAllowStartFgsState = PROCESS_STATE_NONEXISTENT;
 
-    @GuardedBy("mService")
-    private final ArraySet<Binder> mBackgroundFgsStartTokens = new ArraySet<>();
-
     /**
      * Whether or not this process has been in forced-app-standby state.
      */
@@ -1101,21 +1097,6 @@
     }
 
     @GuardedBy("mService")
-    void addAllowBackgroundFgsStartsToken(Binder entity) {
-        mBackgroundFgsStartTokens.add(entity);
-    }
-
-    @GuardedBy("mService")
-    void removeAllowBackgroundFgsStartsToken(Binder entity) {
-        mBackgroundFgsStartTokens.remove(entity);
-    }
-
-    @GuardedBy("mService")
-    boolean areBackgroundFgsStartsAllowedByToken() {
-        return !mBackgroundFgsStartTokens.isEmpty();
-    }
-
-    @GuardedBy("mService")
     void resetAllowStartFgsState() {
         mAllowStartFgsState = PROCESS_STATE_NONEXISTENT;
     }
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
index fd59e85..dbb2f65 100644
--- a/services/core/java/com/android/server/am/ServiceRecord.java
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -149,10 +149,6 @@
     @GuardedBy("ams")
     private List<IBinder> mBgActivityStartsByStartOriginatingTokens = new ArrayList<>();
 
-    // any current binding to this service has BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND
-    // flag? if true, the process can start FGS from background.
-    boolean mIsAllowedBgFgsStartsByBinding;
-
     // allow while-in-use permissions in foreground service or not.
     // while-in-use permissions in FGS started from background might be restricted.
     boolean mAllowWhileInUsePermissionInFgs;
@@ -445,10 +441,6 @@
             pw.print(prefix); pw.print("mIsAllowedBgActivityStartsByStart=");
             pw.println(mIsAllowedBgActivityStartsByStart);
         }
-        if (mIsAllowedBgFgsStartsByBinding) {
-            pw.print(prefix); pw.print("mIsAllowedBgFgsStartsByBinding=");
-            pw.println(mIsAllowedBgFgsStartsByBinding);
-        }
         pw.print(prefix); pw.print("allowWhileInUsePermissionInFgs=");
                 pw.println(mAllowWhileInUsePermissionInFgs);
         pw.print(prefix); pw.print("recentCallingPackage=");
@@ -634,11 +626,6 @@
             } else {
                 proc.removeAllowBackgroundActivityStartsToken(this);
             }
-            if (mIsAllowedBgFgsStartsByBinding) {
-                proc.mState.addAllowBackgroundFgsStartsToken(this);
-            } else {
-                proc.mState.removeAllowBackgroundFgsStartsToken(this);
-            }
         }
         if (app != null && app != proc) {
             // If the old app is allowed to start bg activities because of a service start, leave it
@@ -726,34 +713,11 @@
         setAllowedBgActivityStartsByBinding(isAllowedByBinding);
     }
 
-    void updateIsAllowedBgFgsStartsByBinding() {
-        boolean isAllowedByBinding = false;
-        for (int conni = connections.size() - 1; conni >= 0; conni--) {
-            ArrayList<ConnectionRecord> cr = connections.valueAt(conni);
-            for (int i = 0; i < cr.size(); i++) {
-                if ((cr.get(i).flags
-                        & Context.BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND) != 0) {
-                    isAllowedByBinding = true;
-                    break;
-                }
-            }
-            if (isAllowedByBinding) {
-                break;
-            }
-        }
-        setAllowedBgFgsStartsByBinding(isAllowedByBinding);
-    }
-
     void setAllowedBgActivityStartsByBinding(boolean newValue) {
         mIsAllowedBgActivityStartsByBinding = newValue;
         updateParentProcessBgActivityStartsToken();
     }
 
-    void setAllowedBgFgsStartsByBinding(boolean newValue) {
-        mIsAllowedBgFgsStartsByBinding = newValue;
-        updateParentProcessBgFgsStartsToken();
-    }
-
     /**
      * Called when the service is started with allowBackgroundActivityStarts set. We allow
      * it for background activity starts, setting up a callback to remove this ability after a
@@ -846,17 +810,6 @@
         }
     }
 
-    private void updateParentProcessBgFgsStartsToken() {
-        if (app == null) {
-            return;
-        }
-        if (mIsAllowedBgFgsStartsByBinding) {
-            app.mState.addAllowBackgroundFgsStartsToken(this);
-        } else {
-            app.mState.removeAllowBackgroundFgsStartsToken(this);
-        }
-    }
-
     /**
      * Returns the originating token if that's the only reason background activity starts are
      * allowed. In order for that to happen the service has to be allowed only due to starts, since