Skip to content

Commit a9d9dec

Browse files
author
Maxim Siniavine
committed
Go to home screen after launching each app.
Instead of starting one app after another the MemoryUsage instrumentation goes to the home screen between launching apps. Change-Id: Ia0acf9f6f65a23f537b96c98743b59d746681447
1 parent e2f0ec8 commit a9d9dec

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)