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

Commit 62366ebc authored by Stefan Andonian's avatar Stefan Andonian Committed by Android (Google) Code Review
Browse files

Merge "Use different context to unregisterComponentCallbacks in ViewCapture" into main

parents 33dd985c 8c02ff64
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -11,11 +11,11 @@ import android.view.Window
 */
class NoOpViewCapture: ViewCapture(0, 0,
        createAndStartNewLooperExecutor("NoOpViewCapture", HandlerThread.MIN_PRIORITY)) {
    override fun startCapture(view: View?, name: String?): SafeCloseable {
    override fun startCapture(view: View, name: String): SafeCloseable {
        return SafeCloseable { }
    }

    override fun startCapture(window: Window?): SafeCloseable {
    override fun startCapture(window: Window): SafeCloseable {
        return SafeCloseable { }
    }
}
 No newline at end of file
+6 −6
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public abstract class ViewCapture {
     * Attaches the ViewCapture to the provided window and returns a handle to detach the listener
     */
    @NonNull
    public SafeCloseable startCapture(Window window) {
    public SafeCloseable startCapture(@NonNull Window window) {
        String title = window.getAttributes().getTitle().toString();
        String name = TextUtils.isEmpty(title) ? window.toString() : title;
        return startCapture(window.getDecorView(), name);
@@ -139,16 +139,16 @@ public abstract class ViewCapture {
     * Verifies that ViewCapture is enabled before actually attaching an onDrawListener.
     */
    @NonNull
    public SafeCloseable startCapture(View view, String name) {
    public SafeCloseable startCapture(@NonNull View view, @NonNull String name) {
        WindowListener listener = new WindowListener(view, name);
        if (mIsEnabled) MAIN_EXECUTOR.execute(listener::attachToRoot);
        mListeners.add(listener);

        Context context = view.getContext();
        context.registerComponentCallbacks(listener);
        view.getContext().registerComponentCallbacks(listener);

        return () -> {
            context.unregisterComponentCallbacks(listener);
            if (listener.mRoot != null && listener.mRoot.getContext() != null) {
                listener.mRoot.getContext().unregisterComponentCallbacks(listener);
            }
            mListeners.remove(listener);
            listener.detachFromRoot();
        };