Skip to content

Commit

Permalink
calls androidx.test.platform.app.InstrumentationRegistry.getInstrumen…
Browse files Browse the repository at this point in the history
…tation directly
  • Loading branch information
KazuCocoa committed Dec 27, 2023
1 parent 4b9164f commit 6fb6b38
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.appium.uiautomator2.core;

import android.app.Instrumentation;
import android.app.Service;
import android.app.UiAutomation;
import android.hardware.display.DisplayManager;
Expand All @@ -31,6 +30,8 @@
import static io.appium.uiautomator2.utils.ReflectionUtils.getMethod;
import static io.appium.uiautomator2.utils.ReflectionUtils.invoke;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

public class UiAutomatorBridge {
private static UiAutomatorBridge INSTANCE = null;

Expand Down Expand Up @@ -59,8 +60,9 @@ 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);
// Device.getUiDevice gets the instance via 'androidx.test.platform.app.InstrumentationRegistry.getInstrumentation'
// context, thus here directly calls the method.
DisplayManager displayManager = (DisplayManager) getInstrumentation().getContext().getSystemService(Service.DISPLAY_SERVICE);
return displayManager.getDisplay(Display.DEFAULT_DISPLAY);
}

Expand Down

0 comments on commit 6fb6b38

Please sign in to comment.