summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2016-08-09 01:31:28 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-08-09 01:31:29 +0000
commitc57da63030a844afbba15d242030fc3df967f5ef (patch)
tree03080319bf3527837bd88a3ed22cf1135c6affc0
parent51b4aa90aa096a38563f0e84eeb7326e2414896f (diff)
parent2c0f3a372ce66febe4640d6fd38f055ab466669d (diff)
Merge "Kill service before trying to cancel notifications."
-rw-r--r--packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
index c7c7fc5e7491..902c71d64ae9 100644
--- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
+++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
@@ -588,6 +588,10 @@ public class BugreportReceiverTest extends InstrumentationTestCase {
}
private void cancelExistingNotifications() {
+ // Must kill service first, because notifications from a foreground service cannot be
+ // canceled.
+ killService();
+
NotificationManager nm = NotificationManager.from(mContext);
StatusBarNotification[] activeNotifications = nm.getActiveNotifications();
if (activeNotifications.length == 0) {
@@ -899,6 +903,26 @@ public class BugreportReceiverTest extends InstrumentationTestCase {
fail("Service status didn't change to " + expectRunning);
}
+ private void killService() {
+ String service = BugreportProgressService.class.getName();
+
+ if (!isServiceRunning(service)) return;
+
+ Log.w(TAG, "Service '" + service + "' is still running, killing it");
+ silentlyExecuteShellCommand("am stopservice com.android.shell/.BugreportProgressService");
+
+ waitForService(false);
+ }
+
+ private void silentlyExecuteShellCommand(String cmd) {
+ Log.w(TAG, "silentlyExecuteShellCommand: '" + cmd + "'");
+ try {
+ UiDevice.getInstance(getInstrumentation()).executeShellCommand(cmd);
+ } catch (IOException e) {
+ Log.w(TAG, "error executing shell comamand '" + cmd + "'", e);
+ }
+ }
+
private void createTextFile(String path, String content) throws IOException {
Log.v(TAG, "createFile(" + path + ")");
try (Writer writer = new BufferedWriter(new OutputStreamWriter(