Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +14,6 @@
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;
Expand Down Expand Up @@ -125,31 +123,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
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;
Expand Down Expand Up @@ -295,68 +268,6 @@ private int decodeOrientations(@NonNull JSONArray encodedOrientations)
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 {
Expand Down Expand Up @@ -515,15 +426,6 @@ public interface PlatformMessageHandler {
* {@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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand All @@ -19,7 +18,6 @@
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. */
Expand Down Expand Up @@ -87,16 +85,6 @@ public CharSequence getClipboardData(
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) {
Expand Down Expand Up @@ -299,24 +287,4 @@ private void setClipboardData(String text) {
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);
}
}
2 changes: 0 additions & 2 deletions shell/platform/android/test/io/flutter/FlutterTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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;
Expand Down Expand Up @@ -47,7 +46,6 @@
FlutterRendererTest.class,
FlutterViewTest.class,
InputConnectionAdaptorTest.class,
PlatformChannelTest.class,
PlatformPluginTest.class,
PluginComponentTest.class,
PreconditionsTest.class,
Expand Down
Loading