diff --git a/android/build.gradle b/android/build.gradle index 763ebccef18..70264e3b7ae 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -76,6 +76,7 @@ android { implementation deps.openssl implementation deps.fbjni implementation deps.soloader + implementation deps.curtains implementation deps.jsr305 implementation deps.supportAppCompat implementation deps.supportSqlite diff --git a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt index dc4f6b9fb49..51102e1a27a 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt +++ b/android/src/main/java/com/facebook/flipper/plugins/uidebugger/core/Snapshot.kt @@ -7,7 +7,6 @@ package com.facebook.flipper.plugins.uidebugger.core -import android.app.Activity import android.graphics.Canvas import android.os.Build import android.os.Handler @@ -17,6 +16,7 @@ import android.view.PixelCopy import android.view.View import androidx.annotation.RequiresApi import com.facebook.flipper.plugins.uidebugger.LogTag +import curtains.phoneWindow import kotlin.coroutines.Continuation import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine @@ -92,25 +92,26 @@ class PixelCopySnapshotter( return if (view.isHardwareAccelerated) { SnapshotCommon.doSnapshotWithErrorHandling(bitmapPool, view, fallback) { - tryCopyViaActivityWindow(view, it) || tryCopyViaInternalSurface(view, it) + tryCopyViaPhoneWindow(view, it) || tryCopyViaInternalSurface(view, it) } } else { fallback.takeSnapshot(view) } } - private suspend fun tryCopyViaActivityWindow( + /** + * This is the preferred method, passing a window into pixel copy correctly accounts for the + * surface insets, this means dialog fragments are snapshotted correctly + */ + private suspend fun tryCopyViaPhoneWindow( view: View, bitmap: BitmapPool.ReusableBitmap ): Boolean { - val decorViewToActivity: Map = ActivityTracker.decorViewToActivityMap - - val activityForDecorView = decorViewToActivity[view] ?: return false + val window = view.phoneWindow ?: return false return suspendCoroutine { continuation -> - PixelCopy.request( - activityForDecorView.window, bitmap.bitmap, pixelCopyCallback(continuation), handler) + PixelCopy.request(window, bitmap.bitmap, pixelCopyCallback(continuation), handler) } } diff --git a/build.gradle b/build.gradle index a0e016e7470..e1c92cdccc9 100644 --- a/build.gradle +++ b/build.gradle @@ -78,6 +78,7 @@ ext.deps = [ fbjni : "com.facebook.fbjni:fbjni:$FBJNI_VERSION", screenshot : 'com.facebook.testing.screenshot:core:0.15.0', boltsTasks : 'com.parse.bolts:bolts-tasks:1.4.0', + curtains : 'com.squareup.curtains:curtains:1.2.5', // Third-party websocket : 'org.java-websocket:Java-WebSocket:1.5.4', openssl : 'com.android.ndk.thirdparty:openssl:1.1.1l-beta-1',