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

Commit 18a7d247 authored by Archisha Baranwal's avatar Archisha Baranwal Committed by Android (Google) Code Review
Browse files

Merge "Adding ViewCaptureAwareWindowManager to ClipboardOverlayWindow." into main

parents d0d63d0a 8843fd24
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;

import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
import com.android.internal.policy.PhoneWindow;
import com.android.systemui.clipboardoverlay.dagger.ClipboardOverlayModule.OverlayWindowContext;
import com.android.systemui.screenshot.FloatingWindowUtil;
@@ -44,6 +45,7 @@ public class ClipboardOverlayWindow extends PhoneWindow

    private final Context mContext;
    private final WindowManager mWindowManager;
    private final ViewCaptureAwareWindowManager mViewCaptureAwareWindowManager;
    private final WindowManager.LayoutParams mWindowLayoutParams;

    private boolean mKeyboardVisible;
@@ -52,7 +54,9 @@ public class ClipboardOverlayWindow extends PhoneWindow
    private Runnable mOnOrientationChangeListener;

    @Inject
    ClipboardOverlayWindow(@OverlayWindowContext Context context) {
    ClipboardOverlayWindow(@OverlayWindowContext Context context,
            @OverlayWindowContext ViewCaptureAwareWindowManager viewCaptureAwareWindowManager,
            @OverlayWindowContext WindowManager windowManager) {
        super(context);
        mContext = context;
        mOrientation = mContext.getResources().getConfiguration().orientation;
@@ -61,10 +65,11 @@ public class ClipboardOverlayWindow extends PhoneWindow
        requestFeature(Window.FEATURE_NO_TITLE);
        requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
        setBackgroundDrawableResource(android.R.color.transparent);
        mWindowManager = mContext.getSystemService(WindowManager.class);
        mWindowManager = windowManager;
        mViewCaptureAwareWindowManager = viewCaptureAwareWindowManager;
        mWindowLayoutParams = FloatingWindowUtil.getFloatingWindowParams();
        mWindowLayoutParams.setTitle("ClipboardOverlay");
        setWindowManager(mWindowManager, null, null);
        setWindowManager(windowManager, null, null);
        setWindowFocusable(false);
    }

@@ -81,10 +86,12 @@ public class ClipboardOverlayWindow extends PhoneWindow

        attach();
        withWindowAttached(() -> {
            WindowInsets currentInsets = mWindowManager.getCurrentWindowMetrics().getWindowInsets();
            WindowInsets currentInsets = mWindowManager.getCurrentWindowMetrics()
                    .getWindowInsets();
            mKeyboardVisible = currentInsets.isVisible(WindowInsets.Type.ime());
            peekDecorView().getViewTreeObserver().addOnGlobalLayoutListener(() -> {
                WindowInsets insets = mWindowManager.getCurrentWindowMetrics().getWindowInsets();
                WindowInsets insets = mWindowManager.getCurrentWindowMetrics()
                        .getWindowInsets();
                boolean keyboardVisible = insets.isVisible(WindowInsets.Type.ime());
                if (keyboardVisible != mKeyboardVisible) {
                    mKeyboardVisible = keyboardVisible;
@@ -105,7 +112,7 @@ public class ClipboardOverlayWindow extends PhoneWindow
    void remove() {
        final View decorView = peekDecorView();
        if (decorView != null && decorView.isAttachedToWindow()) {
            mWindowManager.removeViewImmediate(decorView);
            mViewCaptureAwareWindowManager.removeViewImmediate(decorView);
        }
    }

@@ -139,7 +146,7 @@ public class ClipboardOverlayWindow extends PhoneWindow
        if (decorView.isAttachedToWindow()) {
            return;
        }
        mWindowManager.addView(decorView, mWindowLayoutParams);
        mViewCaptureAwareWindowManager.addView(decorView, mWindowLayoutParams);
        decorView.requestApplyInsets();
    }

@@ -160,7 +167,7 @@ public class ClipboardOverlayWindow extends PhoneWindow
        }
        final View decorView = peekDecorView();
        if (decorView != null && decorView.isAttachedToWindow()) {
            mWindowManager.updateViewLayout(decorView, mWindowLayoutParams);
            mViewCaptureAwareWindowManager.updateViewLayout(decorView, mWindowLayoutParams);
        }
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -18,17 +18,24 @@ package com.android.systemui.clipboardoverlay.dagger;

import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;

import static com.android.systemui.Flags.enableViewCaptureTracing;
import static com.android.systemui.util.ConvenienceExtensionsKt.toKotlinLazy;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import android.content.Context;
import android.hardware.display.DisplayManager;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.WindowManager;

import com.android.app.viewcapture.ViewCapture;
import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
import com.android.systemui.clipboardoverlay.ClipboardOverlayView;
import com.android.systemui.res.R;
import com.android.systemui.settings.DisplayTracker;

import dagger.Lazy;
import dagger.Module;
import dagger.Provides;

@@ -61,6 +68,28 @@ public interface ClipboardOverlayModule {
                R.layout.clipboard_overlay, null);
    }

    /**
     *
     */
    @Provides
    @OverlayWindowContext
    static WindowManager provideWindowManager(@OverlayWindowContext Context context) {
        return context.getSystemService(WindowManager.class);
    }

    /**
     *
     */
    @Provides
    @OverlayWindowContext
    static ViewCaptureAwareWindowManager provideViewCaptureAwareWindowManager(
            @OverlayWindowContext WindowManager windowManager,
            Lazy<ViewCapture> daggerLazyViewCapture) {
        return new ViewCaptureAwareWindowManager(windowManager,
                /* lazyViewCapture= */ toKotlinLazy(daggerLazyViewCapture),
                /* isViewCaptureEnabled= */ enableViewCaptureTracing());
    }

    @Qualifier
    @Documented
    @Retention(RUNTIME)