diff options
3 files changed, 46 insertions, 46 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/LegacyScreenshotViewProxy.kt b/packages/SystemUI/src/com/android/systemui/screenshot/LegacyScreenshotViewProxy.kt index 2294fc0be520..d8c38503dbaf 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/LegacyScreenshotViewProxy.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/LegacyScreenshotViewProxy.kt @@ -22,12 +22,14 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.Rect import android.graphics.drawable.Drawable +import android.util.Log import android.view.Display import android.view.LayoutInflater import android.view.ScrollCaptureResponse import android.view.View import android.view.ViewTreeObserver import android.view.WindowInsets +import android.window.OnBackInvokedCallback import android.window.OnBackInvokedDispatcher import com.android.internal.logging.UiEventLogger import com.android.systemui.flags.FeatureFlags @@ -40,7 +42,6 @@ import com.android.systemui.res.R class LegacyScreenshotViewProxy(context: Context) : ScreenshotViewProxy { override val view: ScreenshotView = LayoutInflater.from(context).inflate(R.layout.screenshot, null) as ScreenshotView - override val internalInsetsListener: ViewTreeObserver.OnComputeInternalInsetsListener override val screenshotPreview: View override var defaultDisplay: Int = Display.DEFAULT_DISPLAY @@ -51,6 +52,9 @@ class LegacyScreenshotViewProxy(context: Context) : ScreenshotViewProxy { set(value) { view.setDefaultTimeoutMillis(value) } + override var onBackInvokedCallback: OnBackInvokedCallback = OnBackInvokedCallback { + Log.wtf(TAG, "OnBackInvoked called before being set!") + } override var onKeyListener: View.OnKeyListener? = null set(value) { view.setOnKeyListener(value) @@ -84,7 +88,35 @@ class LegacyScreenshotViewProxy(context: Context) : ScreenshotViewProxy { get() = view.isPendingSharedTransition init { - internalInsetsListener = view + + view.addOnAttachStateChangeListener( + object : View.OnAttachStateChangeListener { + override fun onViewAttachedToWindow(view: View) { + if (LogConfig.DEBUG_INPUT) { + Log.d(TAG, "Registering Predictive Back callback") + } + view + .findOnBackInvokedDispatcher() + ?.registerOnBackInvokedCallback( + OnBackInvokedDispatcher.PRIORITY_DEFAULT, + onBackInvokedCallback + ) + } + + override fun onViewDetachedFromWindow(view: View) { + if (LogConfig.DEBUG_INPUT) { + Log.d(TAG, "Unregistering Predictive Back callback") + } + view + .findOnBackInvokedDispatcher() + ?.unregisterOnBackInvokedCallback(onBackInvokedCallback) + } + } + ) + if (LogConfig.DEBUG_WINDOW) { + Log.d(TAG, "adding OnComputeInternalInsetsListener") + } + view.viewTreeObserver.addOnComputeInternalInsetsListener(view) screenshotPreview = view.screenshotPreview } @@ -139,12 +171,6 @@ class LegacyScreenshotViewProxy(context: Context) : ScreenshotViewProxy { override fun announceForAccessibility(string: String) = view.announceForAccessibility(string) - override fun addOnAttachStateChangeListener(listener: View.OnAttachStateChangeListener) = - view.addOnAttachStateChangeListener(listener) - - override fun findOnBackInvokedDispatcher(): OnBackInvokedDispatcher? = - view.findOnBackInvokedDispatcher() - override fun getViewTreeObserver(): ViewTreeObserver = view.viewTreeObserver override fun post(runnable: Runnable) { @@ -156,4 +182,8 @@ class LegacyScreenshotViewProxy(context: Context) : ScreenshotViewProxy { return LegacyScreenshotViewProxy(context) } } + + companion object { + private const val TAG = "LegacyScreenshotViewProxy" + } } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index 13448d258a2c..1ca9b985b090 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -76,8 +76,6 @@ import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.view.accessibility.AccessibilityManager; import android.widget.Toast; -import android.window.OnBackInvokedCallback; -import android.window.OnBackInvokedDispatcher; import android.window.WindowContext; import com.android.internal.app.ChooserActivity; @@ -265,13 +263,6 @@ public class ScreenshotController { private final UserManager mUserManager; private final AssistContentRequester mAssistContentRequester; - private final OnBackInvokedCallback mOnBackInvokedCallback = () -> { - if (DEBUG_INPUT) { - Log.d(TAG, "Predictive Back callback dispatched"); - } - respondToKeyDismissal(); - }; - private final MessageContainerController mMessageContainerController; private Bitmap mScreenBitmap; private SaveImageInBackgroundTask mSaveInBgTask; @@ -594,27 +585,13 @@ public class ScreenshotController { } mMessageContainerController.setView(mViewProxy.getView()); - mViewProxy.addOnAttachStateChangeListener( - new View.OnAttachStateChangeListener() { - @Override - public void onViewAttachedToWindow(@NonNull View v) { - if (DEBUG_INPUT) { - Log.d(TAG, "Registering Predictive Back callback"); - } - mViewProxy.findOnBackInvokedDispatcher().registerOnBackInvokedCallback( - OnBackInvokedDispatcher.PRIORITY_DEFAULT, mOnBackInvokedCallback); - } - - @Override - public void onViewDetachedFromWindow(@NonNull View v) { - if (DEBUG_INPUT) { - Log.d(TAG, "Unregistering Predictive Back callback"); - } - mViewProxy.findOnBackInvokedDispatcher() - .unregisterOnBackInvokedCallback(mOnBackInvokedCallback); - } - }); mViewProxy.setLogger(mUiEventLogger); + mViewProxy.setOnBackInvokedCallback(() -> { + if (DEBUG_INPUT) { + Log.d(TAG, "Predictive Back callback dispatched"); + } + respondToKeyDismissal(); + }); mViewProxy.setCallbacks(new ScreenshotView.ScreenshotViewCallback() { @Override public void onUserInteraction() { @@ -657,11 +634,6 @@ public class ScreenshotController { }); if (DEBUG_WINDOW) { - Log.d(TAG, "adding OnComputeInternalInsetsListener"); - } - mViewProxy.getViewTreeObserver().addOnComputeInternalInsetsListener( - mViewProxy.getInternalInsetsListener()); - if (DEBUG_WINDOW) { Log.d(TAG, "setContentView: " + mViewProxy.getView()); } setContentView(mViewProxy.getView()); diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotViewProxy.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotViewProxy.kt index 0064521bd3a4..381404a85587 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotViewProxy.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotViewProxy.kt @@ -28,18 +28,18 @@ import android.view.View.OnKeyListener import android.view.ViewGroup import android.view.ViewTreeObserver import android.view.WindowInsets -import android.window.OnBackInvokedDispatcher +import android.window.OnBackInvokedCallback 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 internalInsetsListener: ViewTreeObserver.OnComputeInternalInsetsListener val screenshotPreview: View var defaultDisplay: Int var defaultTimeoutMillis: Long + var onBackInvokedCallback: OnBackInvokedCallback var onKeyListener: OnKeyListener? var flags: FeatureFlags? var packageName: String @@ -78,8 +78,6 @@ interface ScreenshotViewProxy { fun stopInputListening() fun requestFocus() fun announceForAccessibility(string: String) - fun addOnAttachStateChangeListener(listener: View.OnAttachStateChangeListener) - fun findOnBackInvokedDispatcher(): OnBackInvokedDispatcher? fun getViewTreeObserver(): ViewTreeObserver fun post(runnable: Runnable) |