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

Commit 59c72b32 authored by Vania Desmonda's avatar Vania Desmonda
Browse files

Use safer casting asAppHeader() to prevent ClassCastException.

Fixes: 392560338
Test: presubmits
Flag: EXEMPT minor refactoring
Change-Id: I713164b1aba156465e43486ee6ca81968697211d
parent 20cdf105
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -111,14 +111,14 @@ import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;

import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.MainCoroutineDispatcher;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;

import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.MainCoroutineDispatcher;

/**
 * Defines visuals and behaviors of a window decoration of a caption bar and shadows. It works with
 * {@link DesktopModeWindowDecorViewModel}.
@@ -731,13 +731,16 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        } else {
            // App header is visible since `mWindowDecorViewHolder` is of type
            // [AppHeaderViewHolder].
            ((AppHeaderViewHolder) mWindowDecorViewHolder).runOnAppChipGlobalLayout(
            final AppHeaderViewHolder appHeader = asAppHeader(mWindowDecorViewHolder);
            if (appHeader != null) {
                appHeader.runOnAppChipGlobalLayout(
                        () -> {
                            notifyAppHeaderStateChanged();
                            return Unit.INSTANCE;
                        });
            }
        }
    }

    private boolean isCapturedLinkAvailable() {
        return mCapturedLink != null && !mCapturedLink.mUsed;
@@ -766,11 +769,11 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    }

    private void notifyAppHeaderStateChanged() {
        if (isAppHandle(mWindowDecorViewHolder) || mWindowDecorViewHolder == null) {
        final AppHeaderViewHolder appHeader = asAppHeader(mWindowDecorViewHolder);
        if (appHeader == null) {
            return;
        }
        final Rect appChipPositionInWindow =
                ((AppHeaderViewHolder) mWindowDecorViewHolder).getAppChipLocationInWindow();
        final Rect appChipPositionInWindow = appHeader.getAppChipLocationInWindow();
        final Rect taskBounds = mTaskInfo.configuration.windowConfiguration.getBounds();
        final Rect appChipGlobalPosition = new Rect(
                taskBounds.left + appChipPositionInWindow.left,