forked from firka/flutter
Revert getSystemGestureExclusionRects and setSystemGestureExclusionRects (flutter/engine#17613)
* Revert getSystemGestureExclusionRects and setSystemGestureExclusionRects * Remove references to removed PlatformChannelTest.java file
This commit is contained in:
@@ -437,7 +437,6 @@ action("robolectric_tests") {
|
||||
"test/io/flutter/embedding/engine/dart/DartExecutorTest.java",
|
||||
"test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java",
|
||||
"test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java",
|
||||
"test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java",
|
||||
"test/io/flutter/external/FlutterLaunchTests.java",
|
||||
"test/io/flutter/plugin/common/StandardMessageCodecTest.java",
|
||||
"test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java",
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package io.flutter.embedding.engine.systemchannels;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Rect;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -15,7 +14,6 @@ import io.flutter.plugin.common.JSONMethodCodec;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -125,31 +123,6 @@ public class PlatformChannel {
|
||||
platformMessageHandler.popSystemNavigator();
|
||||
result.success(null);
|
||||
break;
|
||||
case "SystemGestures.getSystemGestureExclusionRects":
|
||||
List<Rect> exclusionRects = platformMessageHandler.getSystemGestureExclusionRects();
|
||||
if (exclusionRects == null) {
|
||||
String incorrectApiLevel = "Exclusion rects only exist for Android API 29+.";
|
||||
result.error("error", incorrectApiLevel, null);
|
||||
break;
|
||||
}
|
||||
|
||||
ArrayList<HashMap<String, Integer>> encodedExclusionRects =
|
||||
encodeExclusionRects(exclusionRects);
|
||||
result.success(encodedExclusionRects);
|
||||
break;
|
||||
case "SystemGestures.setSystemGestureExclusionRects":
|
||||
if (!(arguments instanceof JSONArray)) {
|
||||
String inputTypeError =
|
||||
"Input type is incorrect. Ensure that a List<Map<String, int>> is passed as the input for SystemGestureExclusionRects.setSystemGestureExclusionRects.";
|
||||
result.error("inputTypeError", inputTypeError, null);
|
||||
break;
|
||||
}
|
||||
|
||||
JSONArray inputRects = (JSONArray) arguments;
|
||||
ArrayList<Rect> decodedRects = decodeExclusionRects(inputRects);
|
||||
platformMessageHandler.setSystemGestureExclusionRects(decodedRects);
|
||||
result.success(null);
|
||||
break;
|
||||
case "Clipboard.getData":
|
||||
{
|
||||
String contentFormatName = (String) arguments;
|
||||
@@ -295,68 +268,6 @@ public class PlatformChannel {
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a JSONArray of rectangle data into an ArrayList<Rect>.
|
||||
*
|
||||
* <p>Since View.setSystemGestureExclusionRects receives a JSONArray containing JSONObjects, these
|
||||
* values need to be transformed into the expected input of View.setSystemGestureExclusionRects,
|
||||
* which is ArrayList<Rect>.
|
||||
*
|
||||
* <p>This method is used by the SystemGestures.setSystemGestureExclusionRects platform channel.
|
||||
*
|
||||
* @throws JSONException if {@code inputRects} does not contain expected keys and value types.
|
||||
*/
|
||||
@NonNull
|
||||
private ArrayList<Rect> decodeExclusionRects(@NonNull JSONArray inputRects) throws JSONException {
|
||||
ArrayList<Rect> exclusionRects = new ArrayList<Rect>();
|
||||
for (int i = 0; i < inputRects.length(); i++) {
|
||||
JSONObject rect = inputRects.getJSONObject(i);
|
||||
int top;
|
||||
int right;
|
||||
int bottom;
|
||||
int left;
|
||||
|
||||
try {
|
||||
top = rect.getInt("top");
|
||||
right = rect.getInt("right");
|
||||
bottom = rect.getInt("bottom");
|
||||
left = rect.getInt("left");
|
||||
} catch (JSONException exception) {
|
||||
throw new JSONException(
|
||||
"Incorrect JSON data shape. To set system gesture exclusion rects, \n"
|
||||
+ "a JSONObject with top, right, bottom and left values need to be set to int values.");
|
||||
}
|
||||
|
||||
Rect gestureRect = new Rect(left, top, right, bottom);
|
||||
exclusionRects.add(gestureRect);
|
||||
}
|
||||
|
||||
return exclusionRects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a List<Rect> provided by the Android host into an ArrayList<HashMap<String, Integer>>.
|
||||
*
|
||||
* <p>Since View.getSystemGestureExclusionRects returns a list of Rects, these Rects need to be
|
||||
* transformed into UTF-8 encoded JSON messages to be properly decoded by the Flutter framework.
|
||||
*
|
||||
* <p>This method is used by the SystemGestures.getSystemGestureExclusionRects platform channel.
|
||||
*/
|
||||
private ArrayList<HashMap<String, Integer>> encodeExclusionRects(List<Rect> exclusionRects) {
|
||||
ArrayList<HashMap<String, Integer>> encodedExclusionRects =
|
||||
new ArrayList<HashMap<String, Integer>>();
|
||||
for (Rect rect : exclusionRects) {
|
||||
HashMap<String, Integer> rectMap = new HashMap<String, Integer>();
|
||||
rectMap.put("top", rect.top);
|
||||
rectMap.put("right", rect.right);
|
||||
rectMap.put("bottom", rect.bottom);
|
||||
rectMap.put("left", rect.left);
|
||||
encodedExclusionRects.add(rectMap);
|
||||
}
|
||||
|
||||
return encodedExclusionRects;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private AppSwitcherDescription decodeAppSwitcherDescription(
|
||||
@NonNull JSONObject encodedDescription) throws JSONException {
|
||||
@@ -515,15 +426,6 @@ public class PlatformChannel {
|
||||
* {@code text}.
|
||||
*/
|
||||
void setClipboardData(@NonNull String text);
|
||||
|
||||
/** The Flutter application would like to get the system gesture exclusion rects. */
|
||||
List<Rect> getSystemGestureExclusionRects();
|
||||
|
||||
/**
|
||||
* The Flutter application would like to set the system gesture exclusion rects through the
|
||||
* given {@code rects}.
|
||||
*/
|
||||
void setSystemGestureExclusionRects(@NonNull ArrayList<Rect> rects);
|
||||
}
|
||||
|
||||
/** Types of sounds the Android OS can play on behalf of an application. */
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.app.ActivityManager.TaskDescription;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.SoundEffectConstants;
|
||||
@@ -19,7 +18,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Android implementation of the platform plugin. */
|
||||
@@ -87,16 +85,6 @@ public class PlatformPlugin {
|
||||
public void setClipboardData(@NonNull String text) {
|
||||
PlatformPlugin.this.setClipboardData(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Rect> getSystemGestureExclusionRects() {
|
||||
return PlatformPlugin.this.getSystemGestureExclusionRects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemGestureExclusionRects(@NonNull ArrayList<Rect> rects) {
|
||||
PlatformPlugin.this.setSystemGestureExclusionRects(rects);
|
||||
}
|
||||
};
|
||||
|
||||
public PlatformPlugin(Activity activity, PlatformChannel platformChannel) {
|
||||
@@ -299,24 +287,4 @@ public class PlatformPlugin {
|
||||
ClipData clip = ClipData.newPlainText("text label?", text);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
|
||||
private List<Rect> getSystemGestureExclusionRects() {
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
Window window = activity.getWindow();
|
||||
View view = window.getDecorView();
|
||||
return view.getSystemGestureExclusionRects();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setSystemGestureExclusionRects(ArrayList<Rect> rects) {
|
||||
if (Build.VERSION.SDK_INT < 29) {
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = activity.getWindow();
|
||||
View view = window.getDecorView();
|
||||
view.setSystemGestureExclusionRects(rects);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import io.flutter.embedding.engine.FlutterJNITest;
|
||||
import io.flutter.embedding.engine.RenderingComponentTest;
|
||||
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest;
|
||||
import io.flutter.embedding.engine.renderer.FlutterRendererTest;
|
||||
import io.flutter.embedding.engine.systemchannels.PlatformChannelTest;
|
||||
import io.flutter.external.FlutterLaunchTests;
|
||||
import io.flutter.plugin.common.StandardMessageCodecTest;
|
||||
import io.flutter.plugin.editing.InputConnectionAdaptorTest;
|
||||
@@ -47,7 +46,6 @@ import test.io.flutter.embedding.engine.dart.DartExecutorTest;
|
||||
FlutterRendererTest.class,
|
||||
FlutterViewTest.class,
|
||||
InputConnectionAdaptorTest.class,
|
||||
PlatformChannelTest.class,
|
||||
PlatformPluginTest.class,
|
||||
PluginComponentTest.class,
|
||||
PreconditionsTest.class,
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
package io.flutter.embedding.engine.systemchannels;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import io.flutter.embedding.engine.dart.DartExecutor;
|
||||
import io.flutter.embedding.engine.systemchannels.PlatformChannel.PlatformMessageHandler;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PlatformChannelTest {
|
||||
@Test
|
||||
public void itSendsSuccessMessageToFrameworkWhenGettingSystemGestureExclusionRects()
|
||||
throws JSONException {
|
||||
// --- Test Setup ---
|
||||
DartExecutor dartExecutor = mock(DartExecutor.class);
|
||||
PlatformChannel platformChannel = new PlatformChannel(dartExecutor);
|
||||
PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class);
|
||||
platformChannel.setPlatformMessageHandler(platformMessageHandler);
|
||||
Result result = mock(Result.class);
|
||||
|
||||
// Fake API output setup
|
||||
ArrayList<Rect> fakeExclusionRects = new ArrayList<Rect>();
|
||||
Rect gestureRect = new Rect(0, 0, 500, 250);
|
||||
fakeExclusionRects.add(gestureRect);
|
||||
when(platformMessageHandler.getSystemGestureExclusionRects()).thenReturn(fakeExclusionRects);
|
||||
|
||||
// Parsed API output that should be passed to result.success()
|
||||
ArrayList<HashMap<String, Integer>> expectedEncodedOutputRects =
|
||||
new ArrayList<HashMap<String, Integer>>();
|
||||
HashMap<String, Integer> rectMap = new HashMap<String, Integer>();
|
||||
rectMap.put("top", 0);
|
||||
rectMap.put("right", 500);
|
||||
rectMap.put("bottom", 250);
|
||||
rectMap.put("left", 0);
|
||||
expectedEncodedOutputRects.add(rectMap);
|
||||
MethodCall callGetSystemGestureExclusionRects =
|
||||
new MethodCall("SystemGestures.getSystemGestureExclusionRects", null);
|
||||
|
||||
// --- Execute Test ---
|
||||
platformChannel.parsingMethodCallHandler.onMethodCall(
|
||||
callGetSystemGestureExclusionRects, result);
|
||||
|
||||
// --- Verify Results ---
|
||||
verify(result, times(1)).success(expectedEncodedOutputRects);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
itSendsAPILevelErrorWhenAndroidVersionIsTooLowWhenGettingSystemGestureExclusionRects() {
|
||||
// --- Test Setup ---
|
||||
DartExecutor dartExecutor = mock(DartExecutor.class);
|
||||
PlatformChannel platformChannel = new PlatformChannel(dartExecutor);
|
||||
PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class);
|
||||
platformChannel.setPlatformMessageHandler(platformMessageHandler);
|
||||
when(platformMessageHandler.getSystemGestureExclusionRects()).thenReturn(null);
|
||||
Result result = mock(Result.class);
|
||||
|
||||
MethodCall callGetSystemGestureExclusionRects =
|
||||
new MethodCall("SystemGestures.getSystemGestureExclusionRects", null);
|
||||
|
||||
// --- Execute Test ---
|
||||
platformChannel.parsingMethodCallHandler.onMethodCall(
|
||||
callGetSystemGestureExclusionRects, result);
|
||||
|
||||
// --- Verify Results ---
|
||||
verify(result, times(1))
|
||||
.error("error", "Exclusion rects only exist for Android API 29+.", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itSendsSuccessMessageToFrameworkWhenSettingSystemGestureExclusionRects()
|
||||
throws JSONException {
|
||||
// --- Test Setup ---
|
||||
DartExecutor dartExecutor = mock(DartExecutor.class);
|
||||
PlatformChannel platformChannel = new PlatformChannel(dartExecutor);
|
||||
PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class);
|
||||
platformChannel.setPlatformMessageHandler(platformMessageHandler);
|
||||
Result result = mock(Result.class);
|
||||
|
||||
JSONObject jsonRect = new JSONObject();
|
||||
jsonRect.put("top", 0);
|
||||
jsonRect.put("right", 500);
|
||||
jsonRect.put("bottom", 250);
|
||||
jsonRect.put("left", 0);
|
||||
JSONArray jsonExclusionRectsFromPlatform = new JSONArray();
|
||||
jsonExclusionRectsFromPlatform.put(jsonRect);
|
||||
|
||||
MethodCall callSystemGestureExclusionRects =
|
||||
new MethodCall(
|
||||
"SystemGestures.setSystemGestureExclusionRects", jsonExclusionRectsFromPlatform);
|
||||
|
||||
// --- Execute Test ---
|
||||
platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, result);
|
||||
|
||||
// --- Verify Results ---
|
||||
verify(result, times(1)).success(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itProperlyDecodesGestureRectsWhenSettingSystemGestureExclusionRects()
|
||||
throws JSONException {
|
||||
// --- Test Setup ---
|
||||
DartExecutor dartExecutor = mock(DartExecutor.class);
|
||||
PlatformChannel platformChannel = new PlatformChannel(dartExecutor);
|
||||
PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class);
|
||||
platformChannel.setPlatformMessageHandler(platformMessageHandler);
|
||||
Result result = mock(Result.class);
|
||||
|
||||
JSONObject jsonRect = new JSONObject();
|
||||
jsonRect.put("top", 0);
|
||||
jsonRect.put("right", 500);
|
||||
jsonRect.put("bottom", 250);
|
||||
jsonRect.put("left", 0);
|
||||
JSONArray jsonExclusionRectsFromPlatform = new JSONArray();
|
||||
jsonExclusionRectsFromPlatform.put(jsonRect);
|
||||
|
||||
ArrayList<Rect> expectedDecodedRects = new ArrayList<Rect>();
|
||||
Rect gestureRect = new Rect(0, 0, 500, 250);
|
||||
expectedDecodedRects.add(gestureRect);
|
||||
|
||||
MethodCall callSetSystemGestureExclusionRects =
|
||||
new MethodCall(
|
||||
"SystemGestures.setSystemGestureExclusionRects", jsonExclusionRectsFromPlatform);
|
||||
|
||||
// --- Execute Test ---
|
||||
platformChannel.parsingMethodCallHandler.onMethodCall(
|
||||
callSetSystemGestureExclusionRects, result);
|
||||
|
||||
// --- Verify Results ---
|
||||
verify(platformMessageHandler, times(1)).setSystemGestureExclusionRects(expectedDecodedRects);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itSendsJSONInputErrorWhenNonJSONInputIsUsedWhenSettingSystemGestureExclusionRects() {
|
||||
// --- Test Setup ---
|
||||
DartExecutor dartExecutor = mock(DartExecutor.class);
|
||||
PlatformChannel platformChannel = new PlatformChannel(dartExecutor);
|
||||
PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class);
|
||||
platformChannel.setPlatformMessageHandler(platformMessageHandler);
|
||||
Result result = mock(Result.class);
|
||||
|
||||
String nonJsonInput = "Non-JSON";
|
||||
MethodCall callSetSystemGestureExclusionRects =
|
||||
new MethodCall("SystemGestures.setSystemGestureExclusionRects", nonJsonInput);
|
||||
|
||||
// --- Execute Test ---
|
||||
platformChannel.parsingMethodCallHandler.onMethodCall(
|
||||
callSetSystemGestureExclusionRects, result);
|
||||
|
||||
// --- Verify Results ---
|
||||
String inputTypeError =
|
||||
"Input type is incorrect. Ensure that a List<Map<String, int>> is passed as the input for SystemGestureExclusionRects.setSystemGestureExclusionRects.";
|
||||
verify(result, times(1)).error("inputTypeError", inputTypeError, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itSendsJSONErrorWhenIncorrectJSONShapeIsUsedWhenSettingSystemGestureExclusionRects()
|
||||
throws JSONException {
|
||||
// --- Test Setup ---
|
||||
DartExecutor dartExecutor = mock(DartExecutor.class);
|
||||
PlatformChannel platformChannel = new PlatformChannel(dartExecutor);
|
||||
PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class);
|
||||
platformChannel.setPlatformMessageHandler(platformMessageHandler);
|
||||
Result result = mock(Result.class);
|
||||
|
||||
// Add key/value pairs that aren't needed by exclusion rects to simulate incorrect JSON shape
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("arg1", 0);
|
||||
jsonObject.put("arg2", 500);
|
||||
JSONArray inputArray = new JSONArray();
|
||||
inputArray.put(jsonObject);
|
||||
|
||||
MethodCall callSetSystemGestureExclusionRects =
|
||||
new MethodCall("SystemGestures.setSystemGestureExclusionRects", inputArray);
|
||||
|
||||
// --- Execute Test ---
|
||||
platformChannel.parsingMethodCallHandler.onMethodCall(
|
||||
callSetSystemGestureExclusionRects, result);
|
||||
|
||||
// --- Verify Results ---
|
||||
verify(result, times(1))
|
||||
.error(
|
||||
"error",
|
||||
"JSON error: Incorrect JSON data shape. To set system gesture exclusion rects, \n"
|
||||
+ "a JSONObject with top, right, bottom and left values need to be set to int values.",
|
||||
null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user