@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @Override public UiAutomation getUiAutomation() { return base.getUiAutomation(); }
@Override public void setUp() throws Exception{ super.setUp(); Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); AccessibilityNodeInfo root = instrumentation.getUiAutomation().getRootInActiveWindow(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @Override public UiAutomation getUiAutomation() { return base.getUiAutomation(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @Override public UiAutomation getUiAutomation() { return base.getUiAutomation(); }
@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); } }
private void grantAllPermissions() { Context context = InstrumentationRegistry.getTargetContext(); try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS); UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation(); for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) { if ((packageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) { grantReal(uiAutomation, packageInfo.requestedPermissions[i]); } } } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "packageInfo not found for: " + context.getPackageName()); } }
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) { } } }
/** * 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); }
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); } } }
public static boolean record(String msg) { List<AccessibilityWindowInfo> list = InstrumentationRegistry.getInstrumentation().getUiAutomation().getWindows(); for (AccessibilityWindowInfo win : list) { Log.i(TAG_MAIN, win.getClass().getName());
public AutomatorServiceImpl() { device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); this.uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation(); Device.getInstance().init(device, uiAutomation); } /**