package com.xtremelabs.robolectric.shadows; import android.app.ActivityManager; import com.xtremelabs.robolectric.internal.Implementation; import com.xtremelabs.robolectric.internal.Implements; import java.util.ArrayList; import java.util.List; /** * Shadow for the Android {@code ActivityManager} class. */ @SuppressWarnings({"UnusedDeclaration"}) @Implements(ActivityManager.class) public class ShadowActivityManager { private List tasks = new ArrayList(); private List processes = new ArrayList(); private String backgroundPackage; private ActivityManager.MemoryInfo memoryInfo; @Implementation public List getRunningTasks(int maxNum) { return tasks; } @Implementation public List getRunningAppProcesses() { return processes; } @Implementation public void killBackgroundProcesses(String packageName) { backgroundPackage = packageName; } @Implementation public void getMemoryInfo(ActivityManager.MemoryInfo outInfo) { if (memoryInfo != null) { outInfo.lowMemory = memoryInfo.lowMemory; } } /** * Non-Android accessor to set the list of running tasks. * @param tasks */ public void setTasks(List tasks) { this.tasks = tasks; } /** * Non-Android accessor to set the list of running processes. * @param processes */ public void setProcesses( List processes ) { this.processes = processes; } /** * Non-Android accessor, for use in assertions. */ public String getBackgroundPackage() { return backgroundPackage; } public void setMemoryInfo(ActivityManager.MemoryInfo memoryInfo) { this.memoryInfo = memoryInfo; } @Implements(ActivityManager.MemoryInfo.class) public static class ShadowMemoryInfo { public boolean lowMemory; public void setLowMemory(boolean lowMemory) { this.lowMemory = lowMemory; } } }