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

Commit 2f558d26 authored by Christopher Tate's avatar Christopher Tate
Browse files

Defer broadcasts to slow-handling apps

When an app takes a long time to handle broadcasts, we start deferring
further broadcasts to it to make sure that other broadcast traffic in
the system can continue to make progress.  Global delivery order is
technically rearranged, but delivery order from the point of view of any
given app remains consistent with issuance order.

When alarm broadcasts are issued, we prioritize delivery of deferred
alarms to the alarm recipients (i.e. we suspend the deferral policy and
catch up as promptly as possible) in order to minimize wake time spent
waiting for the alarm broadcast to be delivered.  Once an app with a
deferred broadcast backlog is no longer the target of an in-flight
alarm, we re-impose deferral policy on it.

This policy intentionally trades off increased broadcast delivery
latency to apps that take a "long" time to handle broadcasts, in
exchange for lowering delivery latency to all other apps in the system
that would previously have had to wait behind the slow app.

In addition, broadcast dispatch policy parameters can now be overlaid
via the usual global Settings mechanism.  In particular, configuring the
"bcast_slow_time" parameter to a value in milliseconds higher than the
queue's broadcast timeout period will disable the new slow-receiver
policies.

Bug: 111404343
Test: device boots & runs
Test: tests/ActivityTests
Change-Id: I76ac79bdf41ca3cfcc48515bca779ea0f5744c0b
parent 97bd994b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -277,6 +277,7 @@ interface IActivityManager {
    void unstableProviderDied(in IBinder connection);
    boolean isIntentSenderAnActivity(in IIntentSender sender);
    boolean isIntentSenderAForegroundService(in IIntentSender sender);
    boolean isIntentSenderABroadcast(in IIntentSender sender);
    int startActivityAsUser(in IApplicationThread caller, in String callingPackage,
            in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho,
            int requestCode, int flags, in ProfilerInfo profilerInfo,
+13 −0
Original line number Diff line number Diff line
@@ -1111,6 +1111,19 @@ public final class PendingIntent implements Parcelable {
        }
    }

    /**
     * @hide
     * Check whether this PendingIntent will launch an Activity.
     */
    public boolean isBroadcast() {
        try {
            return ActivityManager.getService()
                .isIntentSenderABroadcast(mTarget);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     * Return the Intent of this PendingIntent.
+38 −0
Original line number Diff line number Diff line
@@ -11765,6 +11765,44 @@ public final class Settings {
         */
        public static final String SYNC_MANAGER_CONSTANTS = "sync_manager_constants";
        /**
         * Broadcast dispatch tuning parameters specific to foreground broadcasts.
         *
         * This is encoded as a key=value list, separated by commas. Ex: "foo=1,bar=true"
         *
         * The following keys are supported:
         * <pre>
         * bcast_timeout                (long)
         * bcast_slow_time              (long)
         * bcast_deferral               (long)
         * bcast_deferral_decay_factor  (float)
         * bcast_deferral_floor         (long)
         * </pre>
         *
         * @hide
         */
        public static final String BROADCAST_FG_CONSTANTS = "bcast_fg_constants";
        /**
         * Broadcast dispatch tuning parameters specific to background broadcasts.
         *
         * This is encoded as a key=value list, separated by commas. Ex: "foo=1,bar=true".
         * See {@link #BROADCAST_FG_CONSTANTS} for the list of supported keys.
         *
         * @hide
         */
        public static final String BROADCAST_BG_CONSTANTS = "bcast_bg_constants";
        /**
         * Broadcast dispatch tuning parameters specific to specific "offline" broadcasts.
         *
         * This is encoded as a key=value list, separated by commas. Ex: "foo=1,bar=true".
         * See {@link #BROADCAST_FG_CONSTANTS} for the list of supported keys.
         *
         * @hide
         */
        public static final String BROADCAST_OFFLOAD_CONSTANTS = "bcast_offload_constants";
        /**
         * Whether or not App Standby feature is enabled by system. This controls throttling of apps
         * based on usage patterns and predictions. Platform will turn on this feature if both this
+3 −0
Original line number Diff line number Diff line
@@ -132,6 +132,9 @@ public class SettingsBackupTest {
                    Settings.Global.AUTOMATIC_POWER_SAVER_MODE,
                    Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED,
                    Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY,
                    Settings.Global.BROADCAST_BG_CONSTANTS,
                    Settings.Global.BROADCAST_FG_CONSTANTS,
                    Settings.Global.BROADCAST_OFFLOAD_CONSTANTS,
                    Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
                    Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
                    Settings.Global.BATTERY_SAVER_DEVICE_SPECIFIC_CONSTANTS,
+11 −1
Original line number Diff line number Diff line
@@ -17,5 +17,15 @@
package com.android.server;

public interface AlarmManagerInternal {
    void removeAlarmsForUid(int uid);
    // Some other components in the system server need to know about
    // broadcast alarms currently in flight
    public interface InFlightListener {
        /** There is now an alarm pending delivery to the given app */
        void broadcastAlarmPending(int recipientUid);
        /** A broadcast alarm targeted to the given app has completed delivery */
        void broadcastAlarmComplete(int recipientUid);
    }

    public void removeAlarmsForUid(int uid);
    public void registerInFlightListener(InFlightListener callback);
}
Loading