Skip to content

Commit

Permalink
Update some method signatures for Android T
Browse files Browse the repository at this point in the history
* Add new IWindowSession delegate for T
* Fix reference to Tag.createMockTag for T
* Remove IDisplayManager.getDisplayIds(boolean) (it was reverted)

PiperOrigin-RevId: 459386687
  • Loading branch information
hoisie committed Jul 7, 2022
1 parent aa7030d commit 1e34dec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
@@ -1,5 +1,6 @@
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.S_V2;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
Expand All @@ -25,6 +26,7 @@
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;
Expand Down Expand Up @@ -219,12 +221,18 @@ public void dispatchTagDiscovered_shouldDispatchTagToCallback() {
}

private static Tag createMockTag() {
return ReflectionHelpers.callStaticMethod(
Tag.class,
"createMockTag",
ClassParameter.from(byte[].class, new byte[0]),
ClassParameter.from(int[].class, new int[0]),
ClassParameter.from(Bundle[].class, new Bundle[0]));
if (RuntimeEnvironment.getApiLevel() <= S_V2) {
return Tag.createMockTag(new byte[0], new int[0], new Bundle[0]);
} else {
// Android T and above.
return ReflectionHelpers.callStaticMethod(
Tag.class,
"createMockTag",
ClassParameter.from(byte[].class, new byte[0]),
ClassParameter.from(int[].class, new int[0]),
ClassParameter.from(Bundle[].class, new Bundle[0]),
ClassParameter.from(long.class, 0));
}
}

private void createActivity(ActivityScenario.ActivityAction<Activity> activityAction) {
Expand Down
Expand Up @@ -125,11 +125,6 @@ public int[] getDisplayIds() {
return ids;
}

// Added in Android T
public int[] getDisplayIds(boolean ignoredIncludeDisabled) {
return getDisplayIds();
}

// @Override
public void registerCallback(IDisplayManagerCallback iDisplayManagerCallback)
throws RemoteException {
Expand Down
Expand Up @@ -66,7 +66,9 @@ public static void reset() {
private static synchronized WindowSessionDelegate getWindowSessionDelegate() {
if (windowSessionDelegate == null) {
int apiLevel = RuntimeEnvironment.getApiLevel();
if (apiLevel >= S_V2) {
if (apiLevel >= 33) {
windowSessionDelegate = new WindowSessionDelegateT();
} else if (apiLevel >= S_V2) {
windowSessionDelegate = new WindowSessionDelegateSV2();
} else if (apiLevel >= S) {
windowSessionDelegate = new WindowSessionDelegateS();
Expand Down Expand Up @@ -398,4 +400,22 @@ public int addToDisplayAsUser(
return getAddFlags();
}
}

private static class WindowSessionDelegateT extends WindowSessionDelegateSV2 {
// @Implementation(minSdk = T)
public int addToDisplayAsUser(
IWindow window,
WindowManager.LayoutParams attrs,
int viewVisibility,
int displayId,
int userId,
InsetsVisibilities requestedVisibilities,
InputChannel outInputChannel,
InsetsState outInsetsState,
InsetsSourceControl[] outActiveControls,
Rect outAttachedFrame)
throws RemoteException {
return getAddFlags();
}
}
}

0 comments on commit 1e34dec

Please sign in to comment.