Skip to content

Commit 04d5b9f

Browse files
Maxim SiniavineAndroid (Google) Code Review
authored andcommitted
Merge "Go to home screen after launching each app." into jb-mr1-dev
2 parents 4246f69 + a9d9dec commit 04d5b9f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void testMemory() {
7272
try {
7373
processName = startApp(app);
7474
measureMemory(app, processName, results);
75+
closeApp();
7576
} catch (NameNotFoundException e) {
7677
Log.i(TAG, "Application " + app + " not found");
7778
}
@@ -139,13 +140,22 @@ private String startApp(String appName) throws NameNotFoundException {
139140
return process;
140141
}
141142

143+
private void closeApp() {
144+
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
145+
homeIntent.addCategory(Intent.CATEGORY_HOME);
146+
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
147+
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
148+
getInstrumentation().getContext().startActivity(homeIntent);
149+
sleep(3000);
150+
}
151+
142152
private void measureMemory(String appName, String processName,
143153
Bundle results) {
144154
List<Integer> pssData = new ArrayList<Integer>();
145155
int pss = 0;
146156
int iteration = 0;
147157
while (iteration < MAX_ITERATIONS) {
148-
sleep();
158+
sleep(SLEEP_TIME);
149159
pss = getPss(processName);
150160
Log.i(TAG, appName + "=" + pss);
151161
if (pss < 0) {
@@ -184,9 +194,9 @@ private boolean stabilized(List<Integer> pssData) {
184194
return (diff1 + diff2) < THRESHOLD;
185195
}
186196

187-
private void sleep() {
197+
private void sleep(int time) {
188198
try {
189-
Thread.sleep(SLEEP_TIME);
199+
Thread.sleep(time);
190200
} catch (InterruptedException e) {
191201
// ignore
192202
}

0 commit comments

Comments
 (0)