Skip to content

Commit

Permalink
Set FLAG_HARDWARE_ACCELERATED in ShadowWindow constructor.
Browse files Browse the repository at this point in the history
This is needed for ShadowPixelCopy to work correctly on Android S.

PiperOrigin-RevId: 628494031
  • Loading branch information
JuliaSullivanGoogle authored and Copybara-Service committed Apr 26, 2024
1 parent 4f32042 commit aa7f0a9
Showing 1 changed file with 15 additions and 1 deletion.
Expand Up @@ -4,6 +4,7 @@
import static android.os.Build.VERSION_CODES.N;
import static android.os.Build.VERSION_CODES.Q;
import static android.os.Build.VERSION_CODES.R;
import static android.os.Build.VERSION_CODES.S;
import static org.robolectric.RuntimeEnvironment.getApiLevel;
import static org.robolectric.util.reflector.Reflector.reflector;

Expand All @@ -13,6 +14,7 @@
import android.view.FrameMetrics;
import android.view.Window;
import android.view.Window.OnFrameMetricsAvailableListener;
import android.view.WindowManager;
import java.util.HashSet;
import java.util.Set;
import org.robolectric.annotation.HiddenApi;
Expand Down Expand Up @@ -43,7 +45,16 @@ public static Window create(Context context) throws ClassNotFoundException {
: "com.android.internal.policy.impl.PhoneWindow";
Class<? extends Window> phoneWindowClass =
(Class<? extends Window>) Window.class.getClassLoader().loadClass(className);
return ReflectionHelpers.callConstructor(phoneWindowClass, ClassParameter.from(Context.class, context));
return ReflectionHelpers.callConstructor(
phoneWindowClass, ClassParameter.from(Context.class, context));
}

@Implementation(minSdk = S)
protected void __constructor__(Context context) {
reflector(WindowReflector.class, realWindow).__constructor__(context);
realWindow.setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}

@Implementation
Expand Down Expand Up @@ -139,6 +150,9 @@ public void reportOnFrameMetricsAvailable(
@ForType(Window.class)
interface WindowReflector {

@Direct
void __constructor__(Context context);

@Direct
void setFlags(int flags, int mask);

Expand Down

0 comments on commit aa7f0a9

Please sign in to comment.