aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRex Hoffman <rexhoffman@google.com>2024-04-03 01:19:38 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-03 01:19:38 +0000
commit7298936908b346ee82513a125c8d02dd0e2fb293 (patch)
treecc8a736b38b9f5558e9c91db6ad47646edfdeff4
parentd99da9c64d690b4dc511f6eee2592d10c2f26088 (diff)
parent94f4cd0313bc89aa5b3b2cf47c1303c328fdc8fd (diff)
downloadrobolectric-7298936908b346ee82513a125c8d02dd0e2fb293.tar.gz
Merge changes I03f7eed8,I6127f7a5 into main
* changes: Merging back to aosp, with needed fixes. Add ActivityWindowInfo parameter to ViewRootImpl#dispatchResized
-rw-r--r--shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java18
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java43
2 files changed, 60 insertions, 1 deletions
diff --git a/shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java b/shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java
index d32920217..4226e788a 100644
--- a/shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java
+++ b/shadowapi/src/main/java/org/robolectric/util/ReflectionHelpers.java
@@ -10,6 +10,7 @@ import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
/** Collection of helper methods for calling methods and accessing fields reflectively. */
@SuppressWarnings(value = {"unchecked", "TypeParameterUnusedInFormals", "NewApi"})
@@ -401,6 +402,22 @@ public class ReflectionHelpers {
}
/**
+ * Attempt to load a class.
+ *
+ * @param classLoader The class loader.
+ * @param fullyQualifiedClassName The fully qualified class name.
+ * @return The class object, or null if class is not found.
+ */
+ public static Optional<Class<?>> attemptLoadClass(
+ ClassLoader classLoader, String fullyQualifiedClassName) {
+ try {
+ return Optional.of(classLoader.loadClass(fullyQualifiedClassName));
+ } catch (ClassNotFoundException e) {
+ return Optional.empty();
+ }
+ }
+
+ /**
* Create a new instance of a class
*
* @param cl The class object.
@@ -523,3 +540,4 @@ public class ReflectionHelpers {
}
}
}
+
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java
index 744b1c02e..20749faea 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java
@@ -25,6 +25,7 @@ import android.view.WindowInsets;
import android.view.WindowManager;
import android.window.ClientWindowFrames;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Optional;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
@@ -123,7 +124,46 @@ public class ShadowViewRootImpl {
}
public void callDispatchResized() {
- if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.TIRAMISU) {
+ Optional<Class<?>> activityWindowInfoClass =
+ ReflectionHelpers.attemptLoadClass(
+ this.getClass().getClassLoader(), "android.window.ActivityWindowInfo");
+ if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.UPSIDE_DOWN_CAKE
+ && activityWindowInfoClass.isPresent()) {
+ Display display = getDisplay();
+ Rect frame = new Rect();
+ display.getRectSize(frame);
+
+ ClientWindowFrames frames = new ClientWindowFrames();
+ // set the final field
+ ReflectionHelpers.setField(frames, "frame", frame);
+ final ClassParameter<?>[] parameters =
+ new ClassParameter<?>[] {
+ ClassParameter.from(ClientWindowFrames.class, frames),
+ ClassParameter.from(boolean.class, true), /* reportDraw */
+ ClassParameter.from(
+ MergedConfiguration.class, new MergedConfiguration()), /* mergedConfiguration */
+ ClassParameter.from(InsetsState.class, new InsetsState()), /* insetsState */
+ ClassParameter.from(boolean.class, false), /* forceLayout */
+ ClassParameter.from(boolean.class, false), /* alwaysConsumeSystemBars */
+ ClassParameter.from(int.class, 0), /* displayId */
+ ClassParameter.from(int.class, 0), /* syncSeqId */
+ ClassParameter.from(boolean.class, false), /* dragResizing */
+ ClassParameter.from(
+ activityWindowInfoClass.get(),
+ ReflectionHelpers.newInstance(
+ activityWindowInfoClass.get())) /* activityWindowInfo */
+ };
+ try {
+ ReflectionHelpers.callInstanceMethod(
+ ViewRootImpl.class, realObject, "dispatchResized", parameters);
+ } catch (RuntimeException ex) {
+ ReflectionHelpers.callInstanceMethod(
+ ViewRootImpl.class,
+ realObject,
+ "dispatchResized",
+ Arrays.copyOfRange(parameters, 0, parameters.length - 1));
+ }
+ } else if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.TIRAMISU) {
Display display = getDisplay();
Rect frame = new Rect();
display.getRectSize(frame);
@@ -480,3 +520,4 @@ public class ShadowViewRootImpl {
WindowInsets getWindowInsets(boolean forceConstruct);
}
}
+