Tabnine Logo
UiAutomation
Code IndexAdd Tabnine to your IDE (free)

How to use
UiAutomation
in
android.app

Best Java code snippets using android.app.UiAutomation (Showing top 9 results out of 315)

origin: Neamar/KISS

  @Before
  public void setUp() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      getInstrumentation().getUiAutomation().executeShellCommand(
          "pm grant " + mActivityRule.getActivity().getPackageName()
              + " android.permission.READ_CONTACTS");
    }

    mActivityRule.getActivity();

    // Initialize to default preferences
    KissApplication.getApplication(mActivityRule.getActivity()).getDataHandler().clearHistory();
    PreferenceManager.getDefaultSharedPreferences(mActivityRule.getActivity()).edit().clear().apply();
    PreferenceManager.setDefaultValues(mActivityRule.getActivity(), R.xml.preferences, true);

    // Remove lock screen
    Runnable wakeUpDevice = new Runnable() {
      public void run() {
        mActivityRule.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      }
    };
    mActivityRule.getActivity().runOnUiThread(wakeUpDevice);
  }
}
origin: xiaocong/android-uiautomator-server

public boolean injectInputEvent(int action, float x, float y, int metaState) {
  MotionEvent e = MotionEvent.obtain(SystemClock.uptimeMillis(),
      SystemClock.uptimeMillis(),
      action, x, y, metaState);
  e.setSource(InputDevice.SOURCE_TOUCHSCREEN);
  boolean b = uiAutomation.injectInputEvent(e, true);
  e.recycle();
  return b;
}
origin: Catrobat/Paintroid

@Override
protected void failed(Throwable e, Description description) {
  Log.i(LOG_TAG, "taking screenshot of failed test " + description.getMethodName());
  if (uiAutomation == null) {
    Log.i(LOG_TAG, "api level doesn't support screenshots.");
    return;
  }
  Bitmap screenshot = uiAutomation.takeScreenshot();
  if (screenshot == null) {
    Log.e(LOG_TAG, "failed to take screenshot");
    return;
  }
  File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
      + "/screenshots/" + InstrumentationRegistry.getTargetContext().getPackageName());
  if (!path.exists() && !path.mkdirs()) {
    Log.e(LOG_TAG, "failed to create screenshot path");
  }
  String filename = description.getClassName() + "-" + description.getMethodName() + ".png";
  saveScreenshot(screenshot, new File(path, filename));
}
origin: xiaocong/android-uiautomator-server

  @Override
  public void run() {
    while (!stopLooping) {
      AccessibilityEvent accessibilityEvent = null;
      //return true if the AccessibilityEvent type is NOTIFICATION type
      UiAutomation.AccessibilityEventFilter eventFilter = new UiAutomation.AccessibilityEventFilter() {
        @Override
        public boolean accept(AccessibilityEvent event) {
          return event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
        }
      };
      Runnable runnable = new Runnable() {
        @Override
        public void run() {
          // Not performing any event.
        }
      };
      try {
        //wait for AccessibilityEvent filter
        accessibilityEvent = Device.getInstance().getUiAutomation()
            .executeAndWaitForEvent(runnable /*executable event*/, eventFilter /* event to filter*/, 500 /*time out in ms*/);
      } catch (Exception ignore) {}
      if (accessibilityEvent != null) {
        toastMessages.addAll(accessibilityEvent.getText());
      }
    }
  }
}
origin: Eaway/AppCrawler

public static boolean record(String msg) {
  List<AccessibilityWindowInfo> list = InstrumentationRegistry.getInstrumentation().getUiAutomation().getWindows();
  for (AccessibilityWindowInfo win : list) {
    Log.i(TAG_MAIN, win.getClass().getName());
origin: jksiezni/permissive

 private static void grantReal(UiAutomation automation, String permission) {
  try {
   String targetPackageName = InstrumentationRegistry.getTargetContext().getPackageName();
   ParcelFileDescriptor pfn = automation.executeShellCommand("pm grant " + targetPackageName + " " + permission);
   pfn.close();
  } catch (IOException e) {
   Log.w(TAG, e);
  }
 }
}
origin: com.facebook.testing.screenshot/core

private void grantPermission(Context context, String permission) {
 if (Build.VERSION.SDK_INT < 23) {
  return;
 }
 UiAutomation automation = Registry.getRegistry().instrumentation.getUiAutomation();
 String command =
   String.format(Locale.ENGLISH, "pm grant %s %s", context.getPackageName(), permission);
 ParcelFileDescriptor pfd = automation.executeShellCommand(command);
 InputStream stream = new FileInputStream(pfd.getFileDescriptor());
 try {
  byte[] buffer = new byte[1024];
  while (stream.read(buffer) != -1) {
   // Consume stdout to ensure the command completes
  }
 } catch (IOException ignored) {
 } finally {
  try {
   stream.close();
  } catch (IOException ignored) {
  }
 }
}
origin: nenick/espresso-macchiato

/**
 * Safe way to remove granted permission to you app without app restart.
 */
public static void resetAllPermission() {
  // permissions handling only available since android marshmallow
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    return;
  }
  InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand("pm reset-permissions");
  EspWait.forDelay(DELAY_FOR_COMMAND_EXECUTION);
}
origin: sebaslogen/CleanGUITestArchitecture

private static void grantWritePermissionsForScreenshots() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    try {
      Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
      String appPackage = getTargetContext().getPackageName();
      instrumentation.getUiAutomation().executeShellCommand("pm grant " + appPackage
        + " android.permission.READ_EXTERNAL_STORAGE");
      instrumentation.getUiAutomation().executeShellCommand("pm grant " + appPackage
        + " android.permission.WRITE_EXTERNAL_STORAGE");
    } catch (Exception e) {
      throw new RuntimeException(
        "Exception while granting external storage access to application apk", e);
    }
  }
}
android.appUiAutomation

Most used methods

  • executeShellCommand
  • executeAndWaitForEvent
  • getWindows
  • injectInputEvent
  • takeScreenshot

Popular in Java

  • Making http post requests using okhttp
  • addToBackStack (FragmentTransaction)
  • notifyDataSetChanged (ArrayAdapter)
  • findViewById (Activity)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now