Skip to content

Commit

Permalink
feat: get default display via displaymanager
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Dec 27, 2023
1 parent 1a1d473 commit 4b9164f
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/
package io.appium.uiautomator2.core;

import android.app.Instrumentation;
import android.app.Service;
import android.app.UiAutomation;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.view.Display;
import android.view.accessibility.AccessibilityNodeInfo;

Expand Down Expand Up @@ -54,6 +58,14 @@ public UiAutomation getUiAutomation() {
}

public Display getDefaultDisplay() throws UiAutomator2Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Instrumentation instrumentation = (Instrumentation) invoke(getMethod(UiDevice.class, "getInstrumentation"), Device.getUiDevice());
DisplayManager displayManager = (DisplayManager) instrumentation.getContext().getSystemService(Service.DISPLAY_SERVICE);
return displayManager.getDisplay(Display.DEFAULT_DISPLAY);
}

// "getDefaultDisplay" called inside the UiDevice calls
// https://developer.android.com/reference/android/view/WindowManager#getDefaultDisplay()
return (Display) invoke(getMethod(UiDevice.class, "getDefaultDisplay"), Device.getUiDevice());
}
}

0 comments on commit 4b9164f

Please sign in to comment.