1package com.xtremelabs.robolectric.shadows;
2
3import android.app.ActivityManager;
4import com.xtremelabs.robolectric.internal.Implementation;
5import com.xtremelabs.robolectric.internal.Implements;
6
7import java.util.ArrayList;
8import java.util.List;
9
10/**
11 * Shadow for the Android {@code ActivityManager} class.
12 */
13@SuppressWarnings({"UnusedDeclaration"})
14@Implements(ActivityManager.class)
15public class ShadowActivityManager {
16
17	private List<ActivityManager.RunningTaskInfo> tasks =
18		new ArrayList<ActivityManager.RunningTaskInfo>();
19
20	private List<ActivityManager.RunningAppProcessInfo> processes =
21		new ArrayList<ActivityManager.RunningAppProcessInfo>();
22
23	private String backgroundPackage;
24    private ActivityManager.MemoryInfo memoryInfo;
25
26    @Implementation
27	public List<ActivityManager.RunningTaskInfo> getRunningTasks(int maxNum) {
28		return tasks;
29	}
30
31	@Implementation
32	public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() {
33		return processes;
34	}
35
36	@Implementation
37	public void killBackgroundProcesses(String packageName) {
38		backgroundPackage = packageName;
39	}
40
41    @Implementation
42    public void getMemoryInfo(ActivityManager.MemoryInfo outInfo) {
43        if (memoryInfo != null) {
44            outInfo.lowMemory = memoryInfo.lowMemory;
45        }
46    }
47
48	/**
49	 * Non-Android accessor to set the list of running tasks.
50	 * @param tasks
51	 */
52	public void setTasks(List<ActivityManager.RunningTaskInfo> tasks) {
53		this.tasks = tasks;
54	}
55
56	/**
57	 * Non-Android accessor to set the list of running processes.
58	 * @param processes
59	 */
60	public void setProcesses( List<ActivityManager.RunningAppProcessInfo> processes ) {
61		this.processes = processes;
62	}
63
64	/**
65	 * Non-Android accessor, for use in assertions.
66	 */
67	public String getBackgroundPackage() {
68		return backgroundPackage;
69	}
70
71    public void setMemoryInfo(ActivityManager.MemoryInfo memoryInfo) {
72        this.memoryInfo = memoryInfo;
73    }
74
75    @Implements(ActivityManager.MemoryInfo.class)
76    public static class ShadowMemoryInfo {
77        public boolean lowMemory;
78
79        public void setLowMemory(boolean lowMemory) {
80            this.lowMemory = lowMemory;
81        }
82    }
83}
84