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

Commit 18cedf86 authored by Diego Vela's avatar Diego Vela
Browse files

Call SidecarCallback on main thread.

Call the SidecarCallback on the main thread to avoid deadlocks.
There is a deadlock where the SidecarCallback was running on a binder
thread and a deduplicator in WM jetpack was running on the main thread.
They would have some locks interwovend causing a deadlock. Running on
the main thread will eliminate this.

Flag: androidx.window.sidecar.flags.merge_extensions_sidecar
Bug: 347964255
Test: n/a - analyze the stack traces in the reported bug.
Change-Id: I0e19cd2a2f8b7a63388216fb3b299b0e48f0ae99
parent e77232f6
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import android.app.Activity;
import android.app.ActivityThread;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;

import androidx.annotation.NonNull;
import androidx.window.extensions.layout.FoldingFeature;
@@ -44,11 +46,13 @@ public class SidecarExtensionsImpl implements SidecarInterface {
    private final DeviceStateManager mDeviceStateManager;
    private final DeviceStateManager.DeviceStateCallback mDeviceStateCallback =
            new DeviceStateCallback();
    private final Handler mMainThread;

    public SidecarExtensionsImpl(WindowLayoutComponent windowLayoutComponent,
            DeviceStateManager deviceStateManager) {
        mWindowLayoutComponent = Objects.requireNonNull(windowLayoutComponent);
        mDeviceStateManager = Objects.requireNonNull(deviceStateManager);
        mMainThread = new Handler(Looper.getMainLooper());
    }

    @Override
@@ -189,7 +193,8 @@ public class SidecarExtensionsImpl implements SidecarInterface {
            }
            final SidecarWindowLayoutInfo sidecarWindowLayoutInfo =
                    SidecarExtensionsImpl.computeSidecarWindowLayoutInfo(windowLayoutInfo);
            mSidecarCallback.onWindowLayoutChanged(mWindowToken, sidecarWindowLayoutInfo);
            mMainThread.post(() -> mSidecarCallback
                    .onWindowLayoutChanged(mWindowToken, sidecarWindowLayoutInfo));
        }
    }

@@ -212,7 +217,7 @@ public class SidecarExtensionsImpl implements SidecarInterface {

            final SidecarDeviceState deviceState = new SidecarDeviceState();
            deviceState.posture = posture;
            mSidecarCallback.onDeviceStateChanged(deviceState);
            mMainThread.post(() -> mSidecarCallback.onDeviceStateChanged(deviceState));
        }
    }
}