This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Limit the size of VirtualDisplay we create in android #8704
Merged
iskakaushik
merged 1 commit into
flutter:master
from
iskakaushik:bugfix/limit-virtual-display-size
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,13 @@ | |
|
|
||
| package io.flutter.plugin.platform; | ||
|
|
||
| import static android.view.MotionEvent.PointerCoords; | ||
| import static android.view.MotionEvent.PointerProperties; | ||
|
|
||
| import android.annotation.TargetApi; | ||
| import android.content.Context; | ||
| import android.os.Build; | ||
| import android.util.DisplayMetrics; | ||
| import android.util.Log; | ||
| import android.view.MotionEvent; | ||
| import android.view.View; | ||
|
|
@@ -16,16 +20,13 @@ | |
| import io.flutter.plugin.common.StandardMethodCodec; | ||
| import io.flutter.view.AccessibilityBridge; | ||
| import io.flutter.view.TextureRegistry; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
|
|
||
| import static android.view.MotionEvent.PointerCoords; | ||
| import static android.view.MotionEvent.PointerProperties; | ||
|
|
||
| /** | ||
| * Manages platform views. | ||
| * <p> | ||
|
|
@@ -199,14 +200,18 @@ private void createPlatformView(MethodCall call, MethodChannel.Result result) { | |
| createParams = viewFactory.getCreateArgsCodec().decodeMessage(ByteBuffer.wrap((byte[]) args.get("params"))); | ||
| } | ||
|
|
||
| int physicalWidth = toPhysicalPixels(logicalWidth); | ||
| int physicalHeight = toPhysicalPixels(logicalHeight); | ||
| validateVirtualDisplayDimensions(physicalWidth, physicalHeight); | ||
|
|
||
| TextureRegistry.SurfaceTextureEntry textureEntry = mTextureRegistry.createSurfaceTexture(); | ||
| VirtualDisplayController vdController = VirtualDisplayController.create( | ||
| mContext, | ||
| mAccessibilityEventsDelegate, | ||
| viewFactory, | ||
| textureEntry, | ||
| toPhysicalPixels(logicalWidth), | ||
| toPhysicalPixels(logicalHeight), | ||
| physicalWidth, | ||
| physicalHeight, | ||
| id, | ||
| createParams | ||
| ); | ||
|
|
@@ -261,9 +266,14 @@ private void resizePlatformView(MethodCall call, final MethodChannel.Result resu | |
| ); | ||
| return; | ||
| } | ||
|
|
||
| int physicalWidth = toPhysicalPixels(width); | ||
| int physicalHeight = toPhysicalPixels(height); | ||
| validateVirtualDisplayDimensions(physicalWidth, physicalHeight); | ||
|
|
||
| vdController.resize( | ||
| toPhysicalPixels(width), | ||
| toPhysicalPixels(height), | ||
| physicalWidth, | ||
| physicalHeight, | ||
| new Runnable() { | ||
| @Override | ||
| public void run() { | ||
|
|
@@ -406,6 +416,18 @@ private static PointerCoords parsePointerCoords(Object rawCoords, float density) | |
| return coords; | ||
| } | ||
|
|
||
| private void validateVirtualDisplayDimensions(int width, int height) { | ||
| DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); | ||
| if (height > metrics.heightPixels || width > metrics.widthPixels) { | ||
| StringBuilder errorBuilder = new StringBuilder(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think it's more common in out codebase to just use |
||
| errorBuilder.append("Creating a virtual display of size: "); | ||
| errorBuilder.append(String.format(Locale.ENGLISH, "[%d, %d], ", width, height)); | ||
| errorBuilder.append(" is not supported. It is larger than the device screen size: "); | ||
| errorBuilder.append(String.format(Locale.ENGLISH, "[%d, %d].", metrics.widthPixels, metrics.heightPixels)); | ||
| throw new IllegalArgumentException(errorBuilder.toString()); | ||
| } | ||
| } | ||
|
|
||
| private int toPhysicalPixels(double logicalPixels) { | ||
| float density = mContext.getResources().getDisplayMetrics().density; | ||
| return (int) Math.round(logicalPixels * density); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing context here, but wondering why do we have to be that strict? do we never want to allow VDs bigger than the main display? (if that is the case would be useful to add a comment explaining why we want to be that strict)