• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.app.ActivityManager;
4 import com.xtremelabs.robolectric.internal.Implementation;
5 import com.xtremelabs.robolectric.internal.Implements;
6 
7 import java.util.ArrayList;
8 import java.util.List;
9 
10 /**
11  * Shadow for the Android {@code ActivityManager} class.
12  */
13 @SuppressWarnings({"UnusedDeclaration"})
14 @Implements(ActivityManager.class)
15 public 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
getRunningTasks(int maxNum)27 	public List<ActivityManager.RunningTaskInfo> getRunningTasks(int maxNum) {
28 		return tasks;
29 	}
30 
31 	@Implementation
getRunningAppProcesses()32 	public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() {
33 		return processes;
34 	}
35 
36 	@Implementation
killBackgroundProcesses(String packageName)37 	public void killBackgroundProcesses(String packageName) {
38 		backgroundPackage = packageName;
39 	}
40 
41     @Implementation
getMemoryInfo(ActivityManager.MemoryInfo outInfo)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 	 */
setTasks(List<ActivityManager.RunningTaskInfo> tasks)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 	 */
setProcesses( List<ActivityManager.RunningAppProcessInfo> processes )60 	public void setProcesses( List<ActivityManager.RunningAppProcessInfo> processes ) {
61 		this.processes = processes;
62 	}
63 
64 	/**
65 	 * Non-Android accessor, for use in assertions.
66 	 */
getBackgroundPackage()67 	public String getBackgroundPackage() {
68 		return backgroundPackage;
69 	}
70 
setMemoryInfo(ActivityManager.MemoryInfo memoryInfo)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 
setLowMemory(boolean lowMemory)79         public void setLowMemory(boolean lowMemory) {
80             this.lowMemory = lowMemory;
81         }
82     }
83 }
84