All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowActivityManager Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
package org.robolectric.shadows;

import android.app.ActivityManager;
import android.content.pm.ConfigurationInfo;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

import java.util.ArrayList;
import java.util.List;

/**
 * Shadow for {@link android.app.ActivityManager}.
 */
@Implements(ActivityManager.class)
public class ShadowActivityManager {
  private int memoryClass = 16;
  private String backgroundPackage;
  private ActivityManager.MemoryInfo memoryInfo;
  private final List tasks = new ArrayList<>();
  private final List services = new ArrayList<>();
  private final List processes = new ArrayList<>();

  @Implementation
  public int getMemoryClass() {
    return memoryClass;
  }

  @Implementation
  public static boolean isUserAMonkey() {
    return false;
  }

  @Implementation
  public List getRunningTasks(int maxNum) {
    return tasks;
  }

  @Implementation
  public List getRunningServices(int maxNum) {
    return services;
  }

  @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.availMem = memoryInfo.availMem;
      outInfo.lowMemory = memoryInfo.lowMemory;
      outInfo.threshold = memoryInfo.threshold;
      outInfo.totalMem = memoryInfo.totalMem;
    }
  }

  @Implementation
  public android.content.pm.ConfigurationInfo getDeviceConfigurationInfo() {
    return new ConfigurationInfo();
  }

  /**
   * Non-Android accessor.
   *
   * @param tasks List of running tasks.
   */
  public void setTasks(List tasks) {
    this.tasks.clear();
    this.tasks.addAll(tasks);
  }

  /**
   * Non-Android accessor.
   *
   * @param services List of running services.
   */
  public void setServices(List services) {
    this.services.clear();
    this.services.addAll(services);
  }

  /**
   * Non-Android accessor.
   *
   * @param processes List of running processes.
   */
  public void setProcesses(List processes) {
    this.processes.clear();
    this.processes.addAll(processes);
  }

  /**
   * Non-Android accessor.
   *
   * @return Get the package name of the last background processes killed.
   */
  public String getBackgroundPackage() {
    return backgroundPackage;
  }

  /**
   * Non-Android accessor.
   *
   * @param memoryClass Set the application's memory class.
   */
  public void setMemoryClass(int memoryClass) {
    this.memoryClass = memoryClass;
  }

  /**
   * Non-Android accessor.
   *
   * @param memoryInfo Set the application's memory info.
   */
  public void setMemoryInfo(ActivityManager.MemoryInfo memoryInfo) {
    this.memoryInfo = memoryInfo;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy