congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
UiAutomation.executeShellCommand
Code IndexAdd Tabnine to your IDE (free)

How to use
executeShellCommand
method
in
android.app.UiAutomation

Best Java code snippets using android.app.UiAutomation.executeShellCommand (Showing top 5 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: 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.appUiAutomationexecuteShellCommand

Popular methods of UiAutomation

  • executeAndWaitForEvent
  • getWindows
  • injectInputEvent
  • takeScreenshot

Popular in Java

  • Start an intent from android
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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