in core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java [73:98]
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) {
}
try {
pfd.close();
} catch (IOException ignored) {
}
}
}