diff options
author | Googler <noreply@google.com> | 2024-03-28 13:34:11 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-03-28 13:34:55 -0700 |
commit | 00bfbd923d5b0dcab44d5369412bb81f3ed536c6 (patch) | |
tree | c65635de68203f1a9569124fecb761a2f86eb8f8 /shadows | |
parent | f40250c4eb21e299b4e52e0b151db457d0e5fe64 (diff) | |
download | robolectric-00bfbd923d5b0dcab44d5369412bb81f3ed536c6.tar.gz |
Handle in development changes to rendering logic
Uses reflection as not all in development branches have these changes.
PiperOrigin-RevId: 620042206
Diffstat (limited to 'shadows')
-rw-r--r-- | shadows/framework/src/main/java/org/robolectric/shadows/ShadowViewRootImpl.java | 42 |
1 files changed, 41 insertions, 1 deletions
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..86c2bd02e 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); |