summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2018-10-18 23:52:16 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-10-18 23:52:16 -0700
commit96cb6d97e122562660b4d0be190abb5ea7ab120c (patch)
tree7a4d63361265e54f4f317cdadb9e8a899eaa1200
parent26c2c5e50dd81c2e8ebf7020ef535acc4e668e2b (diff)
parent2417859fa5322ee8238d1650e39c6a950eac3710 (diff)
downloadbase-96cb6d97e122562660b4d0be190abb5ea7ab120c.tar.gz
Merge "Sleep 1s before force stop and use killBackgroundApp"
am: 2417859fa5 Change-Id: I92d83f16123dd16f68eb0d95d83f9dbabd493d01
-rw-r--r--tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java29
1 files changed, 25 insertions, 4 deletions
diff --git a/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java b/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java
index 639ed7d55384..bd8c7dd6bd08 100644
--- a/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java
+++ b/tests/AppLaunch/src/com/android/tests/applaunch/AppLaunch.java
@@ -92,7 +92,9 @@ public class AppLaunch extends InstrumentationTestCase {
"com.google.android.wearable.action.GOOGLE";
private static final int INITIAL_LAUNCH_IDLE_TIMEOUT = 5000; // 5s to allow app to idle
private static final int POST_LAUNCH_IDLE_TIMEOUT = 750; // 750ms idle for non initial launches
- private static final int BETWEEN_LAUNCH_SLEEP_TIMEOUT = 5000; // 5s between launching apps
+ private static final int BEFORE_FORCE_STOP_SLEEP_TIMEOUT = 1000; // 1s before force stopping
+ private static final int BEFORE_KILL_APP_SLEEP_TIMEOUT = 1000; // 1s before killing
+ private static final int BETWEEN_LAUNCH_SLEEP_TIMEOUT = 3000; // 3s between launching apps
private static final int PROFILE_SAVE_SLEEP_TIMEOUT = 1000; // Allow 1s for the profile to save
private static final String LAUNCH_SUB_DIRECTORY = "launch_logs";
private static final String LAUNCH_FILE = "applaunch.txt";
@@ -326,7 +328,14 @@ public class AppLaunch extends InstrumentationTestCase {
}
}
if(mForceStopApp) {
- closeApp(launch.getApp());
+ sleep(BEFORE_FORCE_STOP_SLEEP_TIMEOUT);
+ forceStopApp(launch.getApp());
+ sleep(BEFORE_KILL_APP_SLEEP_TIMEOUT);
+ // Close again for good measure (just in case).
+ forceStopApp(launch.getApp());
+ // Kill the backgrounded process in the case forceStopApp only sent it to
+ // background.
+ killBackgroundApp(launch.getApp());
} else {
startHomeIntent();
}
@@ -637,7 +646,7 @@ public class AppLaunch extends InstrumentationTestCase {
// Kill all the apps
for (String appName : mNameToIntent.keySet()) {
Log.w(TAG, String.format("killing %s", appName));
- closeApp(appName);
+ forceStopApp(appName);
}
// Drop all the cache.
assertNotNull("Issue in dropping the cache",
@@ -645,7 +654,7 @@ public class AppLaunch extends InstrumentationTestCase {
.executeShellCommand(DROP_CACHE_SCRIPT));
}
- private void closeApp(String appName) {
+ private void forceStopApp(String appName) {
Intent startIntent = mNameToIntent.get(appName);
if (startIntent != null) {
String packageName = startIntent.getComponent().getPackageName();
@@ -657,6 +666,18 @@ public class AppLaunch extends InstrumentationTestCase {
}
}
+ private void killBackgroundApp(String appName) {
+ Intent startIntent = mNameToIntent.get(appName);
+ if (startIntent != null) {
+ String packageName = startIntent.getComponent().getPackageName();
+ try {
+ mAm.killBackgroundProcesses(packageName, UserHandle.USER_CURRENT);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error closing app", e);
+ }
+ }
+ }
+
private void sleep(int time) {
try {
Thread.sleep(time);