summaryrefslogtreecommitdiff
path: root/core/java/android/widget/Magnifier.java
diff options
context:
space:
mode:
authorMihai Popa <popam@google.com>2019-05-07 22:29:52 +0100
committerMihai Popa <popam@google.com>2019-05-21 17:08:52 +0100
commit3aa46b2dd00ab9bad26d4f27fa41e0d692afda90 (patch)
treebc5c46fdac2ef3636c1e6d370b120367e88e0f66 /core/java/android/widget/Magnifier.java
parentd263141c4b4dafb198ce773e99cb9a32c5048c6b (diff)
[Magnifier-84] Improve PixelCopy failures handling
The CL adds PixelCopy failure handling in Magnifier. Previously, if the content copy failed, the Magnifier would still render the shadow, therefore displaying an empty rectangle shadow frame. The CL fixes this, avoiding displaying anything if the PixelCopy request fails. Test: atest CtsWidgetTestCases:android.widget.cts.MagnifierTest Bug: 132136368 Change-Id: I66715c56770380afafa5af5a3ee976bcaaa5ba1e
Diffstat (limited to 'core/java/android/widget/Magnifier.java')
-rw-r--r--core/java/android/widget/Magnifier.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/core/java/android/widget/Magnifier.java b/core/java/android/widget/Magnifier.java
index cb5dc5f88b3e..1719015d169d 100644
--- a/core/java/android/widget/Magnifier.java
+++ b/core/java/android/widget/Magnifier.java
@@ -629,7 +629,7 @@ public final class Magnifier {
resolvedTop = Math.min(resolvedTop, mContentCopySurface.mHeight - mSourceHeight);
if (resolvedLeft < 0 || resolvedTop < 0) {
Log.e(TAG, "Magnifier's content is copied from a surface smaller than"
- + "the content requested size. This will probably lead to distorted content.");
+ + "the content requested size. The magnifier will be dismissed.");
}
resolvedRight = Math.max(resolvedRight, resolvedLeft + mSourceWidth);
resolvedBottom = Math.max(resolvedBottom, resolvedTop + mSourceHeight);
@@ -668,6 +668,7 @@ public final class Magnifier {
private void performPixelCopy(final int startXInSurface, final int startYInSurface,
final boolean updateWindowPosition) {
if (mContentCopySurface.mSurface == null || !mContentCopySurface.mSurface.isValid()) {
+ onPixelCopyFailed();
return;
}
@@ -685,6 +686,10 @@ public final class Magnifier {
Bitmap.createBitmap(mSourceWidth, mSourceHeight, Bitmap.Config.ARGB_8888);
PixelCopy.request(mContentCopySurface.mSurface, mPixelCopyRequestRect, bitmap,
result -> {
+ if (result != PixelCopy.SUCCESS) {
+ onPixelCopyFailed();
+ return;
+ }
synchronized (mLock) {
if (mWindow != currentWindowInstance) {
// The magnifier was dismissed (and maybe shown again) in the meantime.
@@ -703,6 +708,17 @@ public final class Magnifier {
mDirtyState = false;
}
+ private void onPixelCopyFailed() {
+ Log.e(TAG, "Magnifier failed to copy content from the view Surface. It will be dismissed.");
+ // Post to make sure #dismiss is done on the main thread.
+ Handler.getMain().postAtFrontOfQueue(() -> {
+ dismiss();
+ if (mCallback != null) {
+ mCallback.onOperationComplete();
+ }
+ });
+ }
+
/**
* Clamp window coordinates inside the surface the magnifier is attached to, to avoid
* displaying the magnifier out of screen or overlapping with system insets.