summaryrefslogtreecommitdiff
path: root/tests/BackgroundDexOptServiceIntegrationTests
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2018-08-09 16:23:22 +0200
committerJorim Jaggi <jjaggi@google.com>2018-08-09 16:51:10 +0200
commit7804f7fae42a72799e6408176f6d56743752caa4 (patch)
tree735b58c5bac0474f1a97ecdf31ac98856c4aef8c /tests/BackgroundDexOptServiceIntegrationTests
parentd2e2541080c454db79d1fd585dc60509ffec6793 (diff)
Fix BackgroundDexOptServiceIntegrationTests
- Ensure that calling uid is shell. - Clear calling identity such that we don't get permission failures when calling getCurrentUser() Test: self Change-Id: Ifbaceb47edbbc4a6b002d49411ca4635ffc33a08 Fixes: 111798412
Diffstat (limited to 'tests/BackgroundDexOptServiceIntegrationTests')
-rw-r--r--tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java33
1 files changed, 13 insertions, 20 deletions
diff --git a/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java b/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java
index e247951f16ef..e509d2d87bf7 100644
--- a/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java
+++ b/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java
@@ -17,8 +17,10 @@
package com.android.server.pm;
import android.app.AlarmManager;
+import android.app.UiAutomation;
import android.content.Context;
import android.os.Environment;
+import android.os.ParcelFileDescriptor;
import android.os.SystemProperties;
import android.os.storage.StorageManager;
import android.support.test.InstrumentationRegistry;
@@ -34,6 +36,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -141,27 +144,17 @@ public final class BackgroundDexOptServiceIntegrationTests {
// Run the command and return the stdout.
private static String runShellCommand(String cmd) throws IOException {
Log.i(TAG, String.format("running command: '%s'", cmd));
- long startTime = System.nanoTime();
- Process p = Runtime.getRuntime().exec(cmd);
- int res;
- try {
- res = p.waitFor();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- String stdout = inputStreamToString(p.getInputStream());
- String stderr = inputStreamToString(p.getErrorStream());
- long elapsedTime = System.nanoTime() - startTime;
- Log.i(TAG, String.format("ran command: '%s' in %d ms with return code %d", cmd,
- TimeUnit.NANOSECONDS.toMillis(elapsedTime), res));
- Log.i(TAG, "stdout");
- Log.i(TAG, stdout);
- Log.i(TAG, "stderr");
- Log.i(TAG, stderr);
- if (res != 0) {
- throw new RuntimeException(String.format("failed command: '%s'", cmd));
+ ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .executeShellCommand(cmd);
+ byte[] buf = new byte[512];
+ int bytesRead;
+ FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
+ StringBuilder stdout = new StringBuilder();
+ while ((bytesRead = fis.read(buf)) != -1) {
+ stdout.append(new String(buf, 0, bytesRead));
}
- return stdout;
+ fis.close();
+ return stdout.toString();
}
// Run the command and return the stdout split by lines.