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

Commit b10079a7 authored by Miranda Kephart's avatar Miranda Kephart Committed by Android (Google) Code Review
Browse files

Merge "Use AssistedFactory for ScreenshotViewProxy" into main

parents e35ff4f3 208e1323
Loading
Loading
Loading
Loading
+20 −17
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.Rect
import android.util.Log
import android.view.Display
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.ScrollCaptureResponse
@@ -37,30 +36,33 @@ import com.android.systemui.flags.FeatureFlags
import com.android.systemui.res.R
import com.android.systemui.screenshot.LogConfig.DEBUG_DISMISS
import com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_DISMISSED_OTHER
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

/**
 * Legacy implementation of screenshot view methods. Just proxies the calls down into the original
 * ScreenshotView.
 */
class LegacyScreenshotViewProxy(private val context: Context, private val logger: UiEventLogger) :
    ScreenshotViewProxy {
class LegacyScreenshotViewProxy
@AssistedInject
constructor(
    private val logger: UiEventLogger,
    flags: FeatureFlags,
    @Assisted private val context: Context,
    @Assisted private val displayId: Int
) : ScreenshotViewProxy {
    override val view: ScreenshotView =
        LayoutInflater.from(context).inflate(R.layout.screenshot, null) as ScreenshotView
    override val screenshotPreview: View
    override var defaultDisplay: Int = Display.DEFAULT_DISPLAY
        set(value) {
            view.setDefaultDisplay(value)
        }
    override var flags: FeatureFlags? = null
        set(value) {
            view.setFlags(value)
        }
    override var packageName: String = ""
        set(value) {
            field = value
            view.setPackageName(value)
        }
    override var callbacks: ScreenshotView.ScreenshotViewCallback? = null
        set(value) {
            field = value
            view.setCallbacks(value)
        }
    override var screenshot: ScreenshotData? = null
@@ -86,6 +88,8 @@ class LegacyScreenshotViewProxy(private val context: Context, private val logger

    init {
        view.setUiEventLogger(logger)
        view.setDefaultDisplay(displayId)
        view.setFlags(flags)
        addPredictiveBackListener { requestDismissal(SCREENSHOT_DISMISSED_OTHER) }
        setOnKeyListener { requestDismissal(SCREENSHOT_DISMISSED_OTHER) }
        if (LogConfig.DEBUG_WINDOW) {
@@ -180,7 +184,7 @@ class LegacyScreenshotViewProxy(private val context: Context, private val logger
            if (LogConfig.DEBUG_INPUT) {
                Log.d(TAG, "Predictive Back callback dispatched")
            }
            onDismissRequested.invoke(ScreenshotEvent.SCREENSHOT_DISMISSED_OTHER)
            onDismissRequested.invoke(SCREENSHOT_DISMISSED_OTHER)
        }
        view.addOnAttachStateChangeListener(
            object : View.OnAttachStateChangeListener {
@@ -215,7 +219,7 @@ class LegacyScreenshotViewProxy(private val context: Context, private val logger
                        if (LogConfig.DEBUG_INPUT) {
                            Log.d(TAG, "onKeyEvent: $keyCode")
                        }
                        onDismissRequested.invoke(ScreenshotEvent.SCREENSHOT_DISMISSED_OTHER)
                        onDismissRequested.invoke(SCREENSHOT_DISMISSED_OTHER)
                        return true
                    }
                    return false
@@ -224,10 +228,9 @@ class LegacyScreenshotViewProxy(private val context: Context, private val logger
        )
    }

    class Factory : ScreenshotViewProxy.Factory {
        override fun getProxy(context: Context, logger: UiEventLogger): ScreenshotViewProxy {
            return LegacyScreenshotViewProxy(context, logger)
        }
    @AssistedFactory
    interface Factory : ScreenshotViewProxy.Factory {
        override fun getProxy(context: Context, displayId: Int): LegacyScreenshotViewProxy
    }

    companion object {
+1 −3
Original line number Diff line number Diff line
@@ -344,7 +344,7 @@ public class ScreenshotController {
        mMessageContainerController = messageContainerController;
        mAssistContentRequester = assistContentRequester;

        mViewProxy = viewProxyFactory.getProxy(mContext, mUiEventLogger);
        mViewProxy = viewProxyFactory.getProxy(mContext, mDisplayId);

        mScreenshotHandler.setOnTimeoutRunnable(() -> {
            if (DEBUG_UI) {
@@ -595,8 +595,6 @@ public class ScreenshotController {
                setWindowFocusable(false);
            }
        });
        mViewProxy.setFlags(mFlags);
        mViewProxy.setDefaultDisplay(mDisplayId);

        if (DEBUG_WINDOW) {
            Log.d(TAG, "setContentView: " + mViewProxy.getView());
+1 −5
Original line number Diff line number Diff line
@@ -25,16 +25,12 @@ import android.view.ScrollCaptureResponse
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import com.android.internal.logging.UiEventLogger
import com.android.systemui.flags.FeatureFlags

/** Abstraction of the surface between ScreenshotController and ScreenshotView */
interface ScreenshotViewProxy {
    val view: ViewGroup
    val screenshotPreview: View

    var defaultDisplay: Int
    var flags: FeatureFlags?
    var packageName: String
    var callbacks: ScreenshotView.ScreenshotViewCallback?
    var screenshot: ScreenshotData?
@@ -73,6 +69,6 @@ interface ScreenshotViewProxy {
    fun prepareEntranceAnimation(runnable: Runnable)

    interface Factory {
        fun getProxy(context: Context, logger: UiEventLogger): ScreenshotViewProxy
        fun getProxy(context: Context, displayId: Int): ScreenshotViewProxy
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ public abstract class ScreenshotModule {
            ScreenshotSoundControllerImpl screenshotSoundProviderImpl);

    @Provides
    static ScreenshotViewProxy.Factory providesScreenshotViewProxyFactory() {
        return new LegacyScreenshotViewProxy.Factory();
    static ScreenshotViewProxy.Factory providesScreenshotViewProxyFactory(
            LegacyScreenshotViewProxy.Factory legacyScreenshotViewProxyFactory) {
        return legacyScreenshotViewProxyFactory;
    }
}