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

Commit c33cbb85 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Offload Luma Sampling IPC to background thread

It's observed that, in the field, SystemUI is ANRing while trying to
register the luma sampling events.

We can offload those to our background executor to keep this from
happening.

Bug: 193922859
Test: manual
Change-Id: Ic5e6c5efa33a166f2e3d81eb12756f606365ae9a
parent 8c67d4c7
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

public class NavigationBarView extends FrameLayout implements
@@ -354,6 +355,7 @@ public class NavigationBarView extends FrameLayout implements
        mEdgeBackGestureHandler = Dependency.get(EdgeBackGestureHandler.Factory.class)
                .create(mContext);
        mEdgeBackGestureHandler.setStateChangeCallback(this::updateStates);
        Executor backgroundExecutor = Dependency.get(Dependency.BACKGROUND_EXECUTOR);
        mRegionSamplingHelper = new RegionSamplingHelper(this,
                new RegionSamplingHelper.SamplingCallback() {
                    @Override
@@ -376,7 +378,7 @@ public class NavigationBarView extends FrameLayout implements
                    public boolean isSamplingEnabled() {
                        return isGesturalModeOnDefaultDisplay(getContext(), mNavBarMode);
                    }
                });
                }, backgroundExecutor);

        mNavBarOverlayController = Dependency.get(NavigationBarOverlayController.class);
        if (mNavBarOverlayController.isNavigationBarOverlayEnabled()) {
+3 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.android.systemui.plugins.NavigationEdgeBackPlugin;
import com.android.systemui.statusbar.VibratorHelper;

import java.io.PrintWriter;
import java.util.concurrent.Executor;

public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPlugin {

@@ -349,6 +350,7 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
                .getDimension(R.dimen.navigation_edge_action_drag_threshold);
        setVisibility(GONE);

        Executor backgroundExecutor = Dependency.get(Dependency.BACKGROUND_EXECUTOR);
        boolean isPrimaryDisplay = mContext.getDisplayId() == DEFAULT_DISPLAY;
        mRegionSamplingHelper = new RegionSamplingHelper(this,
                new RegionSamplingHelper.SamplingCallback() {
@@ -366,7 +368,7 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
                    public boolean isSamplingEnabled() {
                        return isPrimaryDisplay;
                    }
                });
                }, backgroundExecutor);
        mRegionSamplingHelper.setWindowVisible(true);
        mShowProtection = !isPrimaryDisplay;
    }
+14 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.view.ViewTreeObserver;
import com.android.systemui.R;

import java.io.PrintWriter;
import java.util.concurrent.Executor;

/**
 * A helper class to sample regions on the screen and inspect its luminosity.
@@ -52,6 +53,7 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
     */
    private final Rect mRegisteredSamplingBounds = new Rect();
    private final SamplingCallback mCallback;
    private final Executor mBackgroundExecutor;
    private boolean mSamplingEnabled = false;
    private boolean mSamplingListenerRegistered = false;

@@ -82,7 +84,9 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
        }
    };

    public RegionSamplingHelper(View sampledView, SamplingCallback samplingCallback) {
    public RegionSamplingHelper(View sampledView, SamplingCallback samplingCallback,
            Executor backgroundExecutor) {
        mBackgroundExecutor = backgroundExecutor;
        mSamplingListener = new CompositionSamplingListener(
                sampledView.getContext().getMainExecutor()) {
            @Override
@@ -183,10 +187,13 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
                // We only want to reregister if something actually changed
                unregisterSamplingListener();
                mSamplingListenerRegistered = true;
                SurfaceControl registeredStopLayer = stopLayerControl;
                mBackgroundExecutor.execute(() -> {
                    CompositionSamplingListener.register(mSamplingListener, DEFAULT_DISPLAY,
                        stopLayerControl, mSamplingRequestBounds);
                            registeredStopLayer, mSamplingRequestBounds);
                });
                mRegisteredSamplingBounds.set(mSamplingRequestBounds);
                mRegisteredStopLayer = stopLayerControl;
                mRegisteredStopLayer = registeredStopLayer;
            }
            mFirstSamplingAfterStart = false;
        } else {
@@ -199,7 +206,9 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
            mSamplingListenerRegistered = false;
            mRegisteredStopLayer = null;
            mRegisteredSamplingBounds.setEmpty();
            mBackgroundExecutor.execute(() -> {
                CompositionSamplingListener.unregister(mSamplingListener);
            });
        }
    }