- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.text.TextUtils;
-
-import java.io.IOException;
-import java.util.Locale;
-
-public class AndroidProcess implements Parcelable {
-
- /** the process name */
- public final String name;
-
- /** the process id */
- public final int pid;
-
- /**
- * AndroidProcess constructor
- *
- * @param pid
- * the process id
- * @throws IOException
- * if /proc/[pid] does not exist or we don't have read access.
- */
- public AndroidProcess(int pid) throws IOException {
- this.pid = pid;
- this.name = getProcessName(pid);
- }
-
- protected AndroidProcess(Parcel in) {
- this.name = in.readString();
- this.pid = in.readInt();
- }
-
- /**
- * Read the contents of a file in /proc/[pid]/[filename].
- *
- * @param filename
- * the relative path to the file.
- * @return the contents of the file.
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public String read(String filename) throws IOException {
- return ProcFile.readFile(String.format(Locale.ENGLISH, "/proc/%d/%s", pid, filename));
- }
-
- /**
- * /proc/[pid]/attr/current (since Linux 2.6.0)
- *
- * The contents of this file represent the current security attributes of the process.
- *
- * In SELinux, this file is used to get the security context of a process. Prior to Linux
- * 2.6.11, this file could not be used to set the security context (a write was always denied),
- * since SELinux limited process security transitions to execve(2) (see the description of
- * /proc/[pid]/attr/exec, below). ince Linux 2.6.11, SELinux lifted this restriction and began
- * supporting "set" operations via writes to this node if authorized by policy, although use of
- * this operation is only suitable for applications that are trusted to maintain any desired
- * separation between the old and new security contexts. Prior to Linux 2.6.28, SELinux did not
- * allow threads within a multi- threaded process to set their security context via this node as
- * it would yield an inconsistency among the security contexts of the threads sharing the same
- * memory space. Since Linux 2.6.28, SELinux lifted this restriction and began supporting "set"
- * operations for threads within a multithreaded process if the new security context is bounded
- * by the old security context, where the bounded relation is defined in policy and guarantees
- * that the new security context has a subset of the permissions of the old security context.
- * Other security modules may choose to support "set" operations via writes to this node.
- *
- * @return the contents of /proc/[pid]/attr/current
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public String attr_current() throws IOException {
- return read("attr/current");
- }
-
- /**
- * /proc/[pid]/cmdline
- *
- * This read-only file holds the complete command line for the process, unless the process is
- * a zombie. In the latter case, there is nothing in this file: that is, a read on this file will
- * return 0 characters. The command-line arguments appear in this file as a set of strings
- * separated by null bytes ('\0'), with a further null byte after the last string.
- *
- * @return the name of the process. (note: process name may be empty. In case it is empty get
- * the process name from /proc/[pid]/stat).
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- * @see #name
- */
- public String cmdline() throws IOException {
- return read("cmdline");
- }
-
- /**
- * /proc/[pid]/cgroup (since Linux 2.6.24)
- *
- * This file describes control groups to which the process/task belongs. For each cgroup
- * hierarchy there is one entry containing colon-separated fields of the form:
- *
- * 5:cpuacct,cpu,cpuset:/daemons
- *
- * The colon-separated fields are, from left to right:
- *
- *
- * - hierarchy ID number
- * - set of subsystems bound to the hierarchy
- * - control group in the hierarchy to which the process belongs
- *
- *
- * This file is present only if the CONFIG_CGROUPS kernel configuration option is enabled.
- *
- * @return the {@link Cgroup} for this process
- * @throws IOException
- */
- public Cgroup cgroup() throws IOException {
- return Cgroup.get(pid);
- }
-
- /**
- * /proc/[pid]/oom_score (since Linux 2.6.11)
- *
- * This file displays the current score that the kernel gives to this process for the
- * purpose of selecting a process for the OOM-killer. A higher score means that the
- * process is more likely to be selected by the OOM-killer.
- *
- * The basis for this score is the amount of memory used by the process, with
- * increases (+) or decreases (-) for factors including:
- *
- *
- * - whether the process creates a lot of children using fork(2)(+);
- * - whether the process has been running a long time, or has used a lot of CPU time (-);
- * - whether the process has a low nice value (i.e., > 0) (+);
- * - whether the process is privileged (-); and
- * - whether the process is making direct hardware access (-).
- *
- *
- * The oom_score also reflects the adjustment specified by the oom_score_adj
- * or oom_adj setting for the process.
- *
- * @return the oom_score value for this process
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public int oom_score() throws IOException {
- return Integer.parseInt(read("oom_score"));
- }
-
- /**
- * /proc/[pid]/oom_adj (since Linux 2.6.11)
- *
- * This file can be used to adjust the score used to select which process should be killed in
- * an out-of-memory (OOM) situation. The kernel uses this value for a bit-shift operation of the
- * process's oom_score value: valid values are in the* range -16 to +15, plus the special value
- * -17, which disables OOM-killing altogether for this process. A positive score increases the
- * likelihood of this process being killed by the OOM-killer; a negative score decreases the
- * likelihood.
- *
- * The default value for this file is 0; a new process inherits its parent's oom_adj setting.
- * A process must be privileged (CAP_SYS_RESOURCE) to update this file.
- *
- * Since Linux 2.6.36, use of this file is deprecated in favor of
- * /proc/[pid]/oom_score_adj.
- *
- * @return the oom_adj value for this process
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public int oom_adj() throws IOException {
- return Integer.parseInt(read("oom_adj"));
- }
-
- /**
- * /proc/[pid]/oom_score_adj (since Linux 2.6.36)
- *
- * This file can be used to adjust the badness heuristic used to select which process gets
- * killed in out-of-memory conditions.
- *
- * The badness heuristic assigns a value to each candidate task ranging from 0 (never kill) to
- * 1000 (always kill) to determine which process is targeted. The units are roughly a proportion
- * along that range of allowed memory the process may allocate from, based on an estimation of
- * its current memory and swap use. For example, if a task is using all allowed memory, its
- * badness score will be 1000. If it is using half of its allowed memory, its score will be
- * 500.
- *
- * There is an additional factor included in the badness score: root processes are given 3%
- * extra memory over other tasks.
- *
- * The amount of "allowed" memory depends on the context in which the OOM-killer was called.
- * If it is due to the memory assigned to the allocating task's cpuset being exhausted, the
- * allowed memory represents the set of mems assigned to that cpuset (see cpuset(7)). If it is
- * due to a mempolicy's node(s) being exhausted, the allowed memory represents the set of
- * mempolicy nodes. If it is due to a memory limit (or swap limit) being reached, the allowed
- * memory is that configured limit. Finally, if it is due to the entire system being out of
- * memory, the allowed memory represents all allocatable resources.
- *
- * The value of oom_score_adj is added to the badness score before it is used to determine
- * which task to kill. Acceptable values range from -1000 (OOM_SCORE_ADJ_MIN) to +1000
- * (OOM_SCORE_ADJ_MAX). This allows user space to control the preference for OOM-killing, ranging
- * from always preferring a certain task or completely disabling it from OOM killing. The lowest
- * possible value, -1000, is equivalent to disabling OOM- killing entirely for that task, since
- * it will always report a badness score of 0.
- *
- * Consequently, it is very simple for user space to define the amount of memory to consider
- * for each task. Setting a oom_score_adj value of +500, for example, is roughly equivalent to
- * allowing the remainder of tasks sharing the same system, cpuset, mempolicy, or memory
- * controller resources to use at least 50% more memory. A value of -500, on the other hand,
- * would be roughly equivalent to discounting 50% of the task's allowed memory from being
- * considered as scoring against the task.
- *
- * For backward compatibility with previous kernels, /proc/[pid]/oom_adj can still be used to
- * tune the badness score. Its value is scaled linearly with oom_score_adj.
- *
- * Writing to /proc/[pid]/oom_score_adj or /proc/[pid]/oom_adj will change the other with its
- * scaled value.
- *
- * @return the oom_score_adj value for this process
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public int oom_score_adj() throws IOException {
- return Integer.parseInt(read("oom_score_adj"));
- }
-
- /**
- * /proc/[pid]/stat
- *
- * Status information about the process. This is used by ps(1). It is defined in the kernel
- * source file fs/proc/array.c.
- *
- * The fields, in order, with their proper scanf(3) format specifiers, are:
- *
- *
- *
- * - pid %d The process ID.
- *
- * - comm %s The filename of the executable, in parentheses. This is visible whether or not
- * the executable is swapped out.
- *
- * - state %c One of the following characters, indicating process state:
- *
- * - R Running
- * - S Sleeping in an interruptible wait
- * - D Waiting in uninterruptible disk sleep
- * - Z Zombie
- * - T Stopped (on a signal) or (before Linux 2.6.33) trace stopped
- * - t Tracing stop (Linux 2.6.33 onward)
- * - W Paging (only before Linux 2.6.0)
- * - X Dead (from Linux 2.6.0 onward)
- * - x Dead (Linux 2.6.33 to 3.13 only)
- * - K Wakekill (Linux 2.6.33 to 3.13 only)
- * - W Waking (Linux 2.6.33 to 3.13 only)
- * - P Parked (Linux 3.9 to 3.13 only)
- *
- *
- *
- * - ppid %d The PID of the parent of this process.
- *
- * - pgrp %d The process group ID of the process.
- *
- * - session %d The session ID of the process.
- *
- * - tty_nr %d The controlling terminal of the process. (The minor device number is contained
- * in the combination of bits 31 to 20 and 7 to 0; the major device number is in bits 15 to 8.)
- *
- *
- * - tpgid %d The ID of the foreground process group of the controlling terminal of the
- * process.
- *
- * - flags %u The kernel flags word of the process. For bit meanings, see the PF_* defines in
- * the Linux kernel source file include/linux/sched.h. Details depend on the kernel version.
- * The format for this field was %lu before Linux 2.6.
- *
- * - minflt %lu The number of minor faults the process has made which have not required
- * loading a memory page from disk.
- *
- * - cminflt %lu The number of minor faults that the process's waited-for children have
- * made
- *
- * - majflt %lu The number of major faults the process has made which have required loading a
- * memory page from disk.
- *
- * - cmajflt %lu The number of major faults that the process's waited-for children have
- * made
- *
- * - utime %lu Amount of time that this process has been scheduled in user mode, measured in
- * clock ticks (divide by sysconf(_SC_CLK_TCK)). This includes guest time, guest_time (time
- * spent running a virtual CPU, see below), so that applications that are not aware of the guest
- * time field do not lose that time from their calculations.
- *
- * - stime %lu Amount of time that this process has been scheduled in kernel mode, measured
- * in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- *
- * - cutime %ld Amount of time that this process's waited-for children have been scheduled in
- * user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)). (See also times(2).)
- * This includes guest time, cguest_time (time spent running a virtual CPU, see below).
- *
- * - cstime %ld Amount of time that this process's waited-for children have been scheduled in
- * kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- *
- * - priority %ld (Explanation for Linux 2.6) For processes running a real-time scheduling
- * policy (policy below; see sched_setscheduler(2)), this is the negated scheduling priority,
- * minus one; that is, a number in the range -2 to -100, corresponding to real-time priorities 1
- * to 99. For processes running under a non-real-time scheduling policy, this is the raw nice
- * value (setpriority(2)) as represented in the kernel. The kernel stores nice values as numbers
- * in the range 0 (high) to 39 (low), corresponding to the user-visible nice range of -20 to 19.
- * Before Linux 2.6, this was a scaled value based on the scheduler weighting given to this
- * process
- *
- * - nice %ld The nice value (see setpriority(2)), a value in the range 19 (low priority) to
- * -20 (high priority).
- *
- * - num_threads %ld Number of threads in this process (since Linux 2.6). Before kernel 2.6,
- * this field was hard coded to 0 as a placeholder for an earlier removed field.
- *
- * - itrealvalue %ld The time in jiffies before the next SIGALRM is sent to the process due
- * to an interval timer. Since kernel 2.6.17, this field is no longer maintained, and is hard
- * coded as 0.
- *
- * - starttime %llu The time the process started after system boot. In kernels before Linux
- * 2.6, this value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock
- * ticks (divide by sysconf(_SC_CLK_TCK)).
- *
- * - The format for this field was %lu before Linux 2.6. (23) vsize %lu Virtual memory size
- * in bytes.
- *
- * - rss %ld Resident Set Size: number of pages the process has in real memory. This is just
- * the pages which count toward text, data, or stack space. This does not include pages which
- * have not been demand-loaded in, or which are swapped out.
- *
- * - rsslim %lu Current soft limit in bytes on the rss of the process; see the description of
- * RLIMIT_RSS in getrlimit(2).
- *
- * - startcode %lu The address above which program text can run.
- *
- * - endcode %lu The address below which program text can run.
- *
- * - startstack %lu The address of the start (i.e., bottom) of the stack.
- *
- * - kstkesp %lu The current value of ESP (stack pointer), as found in the kernel stack page
- * for the process.
- *
- * - kstkeip %lu The current EIP (instruction pointer).
- *
- * - signal %lu The bitmap of pending signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead
- *
- * - blocked %lu The bitmap of blocked signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead
- *
- * - sigignore %lu The bitmap of ignored signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead
- *
- * - sigcatch %lu The bitmap of caught signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead.
- *
- * - wchan %lu This is the "channel" in which the process is waiting. It is the address of a
- * location in the kernel where the process is sleeping. The corresponding symbolic name can be
- * found in /proc/[pid]/wchan.
- *
- * - nswap %lu Number of pages swapped (not maintained).
- *
- * - cnswap %lu Cumulative nswap for child processes (not maintained).
- *
- * - exit_signal %d (since Linux 2.1.22) Signal to be sent to parent when we die.
- *
- * - processor %d (since Linux 2.2.8) CPU number last executed on.
- *
- * - rt_priority %u (since Linux 2.5.19) Real-time scheduling priority, a number in the
- * range 1 to 99 for processes scheduled under a real-time policy, or 0, for non-real-time
- * processes (see sched_setscheduler(2)).
- *
- * - policy %u (since Linux 2.5.19) Scheduling policy (see sched_setscheduler(2)). Decode
- * using the SCHED_* constants in linux/sched.h. The format for this field was %lu before Linux
- * 2.6.22.
- *
- * - delayacct_blkio_ticks %llu (since Linux 2.6.18) Aggregated block I/O delays, measured
- * in clock ticks (centiseconds).
- *
- * - guest_time %lu (since Linux 2.6.24) Guest time of the process (time spent running a
- * virtual CPU for a guest operating system), measured in clock ticks (divide by
- * sysconf(_SC_CLK_TCK)).
- *
- * - cguest_time %ld (since Linux 2.6.24) Guest time of the process's children, measured in
- * clock ticks (divide by sysconf(_SC_CLK_TCK)).
- *
- * - start_data %lu (since Linux 3.3) Address above which program initialized and
- * uninitialized (BSS) data are placed.
- *
- * - end_data %lu (since Linux 3.3) Address below which program initialized and
- * uninitialized (BSS) data are placed.
- *
- * - start_brk %lu (since Linux 3.3) Address above which program heap can be expanded with
- * brk(2).
- *
- * - arg_start %lu (since Linux 3.5) Address above which program command-line arguments
- * (argv) are placed.
- *
- * - arg_end %lu (since Linux 3.5) Address below program command-line arguments (argv) are
- * placed.
- *
- * - env_start %lu (since Linux 3.5) Address above which program environment is placed.
- *
- * - env_end %lu (since Linux 3.5) Address below which program environment is placed.
- *
- * - exit_code %d (since Linux 3.5) The thread's exit status in the form reported by
- * waitpid(2).
- *
- *
- *
- * @return the {@link Stat} for this process
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public Stat stat() throws IOException {
- return Stat.get(pid);
- }
-
- /**
- * Provides information about memory usage, measured in pages.
- *
- * The columns are:
- *
- *
- * - size (1) total program size (same as VmSize in /proc/[pid]/status)
- * - resident (2) resident set size (same as VmRSS in /proc/[pid]/status)
- * - share (3) shared pages (i.e., backed by a file)
- * - text (4) text (code)
- * - lib (5) library (unused in Linux 2.6)
- * - data (6) data + stack
- * - dt (7) dirty pages (unused in Linux 2.6)
- *
- *
- * @return the {@link Statm} for this process
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public Statm statm() throws IOException {
- return Statm.get(pid);
- }
-
- /**
- * /proc/[pid]/status
- *
- * Provides much of the information in /proc/[pid]/stat and /proc/[pid]/statm in a format
- * that's
- * easier for humans to parse.
- *
- * Here's an example:
- *
- *
- * $ cat /proc/$$/status
- * Name: bash
- * State: S (sleeping)
- * Tgid: 3515
- * Pid: 3515
- * PPid: 3452
- * TracerPid: 0
- * Uid: 1000 1000 1000 1000
- * Gid: 100 100 100 100
- * FDSize: 256
- * Groups: 16 33 100
- * VmPeak: 9136 kB
- * VmSize: 7896 kB
- * VmLck: 0 kB
- * VmPin: 0 kB
- * VmHWM: 7572 kB
- * VmRSS: 6316 kB
- * VmData: 5224 kB
- * VmStk: 88 kB
- * VmExe: 572 kB
- * VmLib: 1708 kB
- * VmPMD: 4 kB
- * VmPTE: 20 kB
- * VmSwap: 0 kB
- * Threads: 1
- * SigQ: 0/3067
- * SigPnd: 0000000000000000
- * ShdPnd: 0000000000000000
- * SigBlk: 0000000000010000
- * SigIgn: 0000000000384004
- * SigCgt: 000000004b813efb
- * CapInh: 0000000000000000
- * CapPrm: 0000000000000000
- * CapEff: 0000000000000000
- * CapBnd: ffffffffffffffff
- * Seccomp: 0
- * Cpus_allowed: 00000001
- * Cpus_allowed_list: 0
- * Mems_allowed: 1
- * Mems_allowed_list: 0
- * voluntary_ctxt_switches: 150
- * nonvoluntary_ctxt_switches: 545
- *
- *
- * The fields are as follows:
- *
- *
- * - Name: Command run by this process.
- * - State: Current state of the process. One of "R (running)", "S (sleeping)", "D (disk
- * sleep)",
- * "T (stopped)", "T (tracing stop)", "Z (zombie)", or "X (dead)".
- * - Tgid: Thread group ID (i.e., Process ID).
- * - Pid: Thread ID (see gettid(2)).
- * - PPid: PID of parent process.
- * - TracerPid: PID of process tracing this process (0 if not being traced).
- * - Uid, Gid: Real, effective, saved set, and filesystem UIDs (GIDs).
- * - FDSize: Number of file descriptor slots currently allocated.
- * - Groups: Supplementary group list.
- * - VmPeak: Peak virtual memory size.
- * - VmSize: Virtual memory size.
- * - VmLck: Locked memory size (see mlock(3)).
- * - VmPin: Pinned memory size (since Linux 3.2). These are pages that can't be moved because
- * something needs to directly access physical memory.
- * - VmHWM: Peak resident set size ("high water mark").
- * - VmRSS: Resident set size.
- * - VmData, VmStk, VmExe: Size of data, stack, and text segments.
- * - VmLib: Shared library code size.
- * - VmPTE: Page table entries size (since Linux 2.6.10).
- * - VmPMD: Size of second-level page tables (since Linux 4.0).
- * - VmSwap: Swapped-out virtual memory size by anonymous private pages; shmem swap usage is
- * not
- * included (since Linux 2.6.34).
- * - Threads: Number of threads in process containing this thread.
- * - SigQ: This field contains two slash-separated numbers that relate to queued signals for
- * the
- * real user ID of this process. The first of these is the number of currently queued signals
- * for
- * this real user ID, and the second is the resource limit on the number of queued signals for
- * this
- * process (see the description of RLIMIT_SIGPENDING in getrlimit(2)).
- * - SigPnd, ShdPnd: Number of signals pending for thread and for process as a whole (see
- * pthreads(7) and signal(7)).
- * - SigBlk, SigIgn, SigCgt: Masks indicating signals being blocked, ignored, and caught (see
- * signal(7)).
- * - CapInh, CapPrm, CapEff: Masks of capabilities enabled in inheritable, permitted, and
- * effective sets (see capabilities(7)).
- * - CapBnd: Capability Bounding set (since Linux 2.6.26, see capabilities(7)).
- * - Seccomp: Seccomp mode of the process (since Linux 3.8, see seccomp(2)). 0 means
- * SECCOMP_MODE_DISABLED; 1 means SECCOMP_MODE_STRICT; 2 means SECCOMP_MODE_FILTER. This field is
- * provided only if the kernel was built with the CONFIG_SECCOMP kernel configuration option
- * enabled.
- * - Cpus_allowed: Mask of CPUs on which this process may run (since Linux 2.6.24, see
- * cpuset(7)).
- * - Cpus_allowed_list: Same as previous, but in "list format" (since Linux 2.6.26, see
- * cpuset(7)).
- * - Mems_allowed: Mask of memory nodes allowed to this process (since Linux 2.6.24, see
- * cpuset(7)).
- * - Mems_allowed_list: Same as previous, but in "list format" (since Linux 2.6.26, see
- * cpuset(7)).
- * voluntary_ctxt_switches, nonvoluntary_ctxt_switches: Number of voluntary and involuntary
- * context
- * switches (since Linux 2.6.23).
- *
- *
- * @return the {@link Status} for this process
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public Status status() throws IOException {
- return Status.get(pid);
- }
-
- /**
- * The symbolic name corresponding to the location in the kernel where the process is sleeping.
- *
- * @return the contents of /proc/[pid]/wchan
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public String wchan() throws IOException {
- return read("wchan");
- }
-
- /**
- * Get the name of a running process.
- *
- * @param pid
- * the process id.
- * @return the name of the process.
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- private String getProcessName(int pid) throws IOException {
- String cmdline = null;
- try {
- cmdline = ProcFile.readFile(String.format(Locale.ENGLISH, "/proc/%d/cmdline", pid)).trim();
- } catch (IOException ignored) {
- }
- if (TextUtils.isEmpty(cmdline)) {
- try {
- return Stat.get(pid).getComm();
- } catch (Exception e) {
- throw new IOException(String.format(Locale.ENGLISH, "Error reading /proc/%d/stat", pid));
- }
- }
- return cmdline;
- }
-
- @Override public int describeContents() {
- return 0;
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(this.name);
- dest.writeInt(this.pid);
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public AndroidProcess createFromParcel(Parcel source) {
- return new AndroidProcess(source);
- }
-
- @Override public AndroidProcess[] newArray(int size) {
- return new AndroidProcess[size];
- }
- };
-
-}
diff --git a/library-main/src/main/java/com/jaredrummler/android/processes/models/Cgroup.java b/library-main/src/main/java/com/jaredrummler/android/processes/models/Cgroup.java
deleted file mode 100644
index 98742b7..0000000
--- a/library-main/src/main/java/com/jaredrummler/android/processes/models/Cgroup.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2015. Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Locale;
-
-/**
- * /proc/[pid]/cgroup (since Linux 2.6.24)
- *
- * This file describes control groups to which the process/task belongs. For each cgroup
- * hierarchy there is one entry containing colon-separated fields of the form:
- *
- * 5:cpuacct,cpu,cpuset:/daemons
- *
- * The colon-separated fields are, from left to right:
- *
- *
- * - hierarchy ID number
- * - set of subsystems bound to the hierarchy
- * - control group in the hierarchy to which the process belongs
- *
- *
- * This file is present only if the CONFIG_CGROUPS kernel configuration option is enabled.
- *
- * @see ControlGroup
- */
-public final class Cgroup extends ProcFile {
-
- /**
- * Read /proc/[pid]/cgroup.
- *
- * @param pid
- * the processes id.
- * @return the {@link Cgroup}
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public static Cgroup get(int pid) throws IOException {
- return new Cgroup(String.format(Locale.ENGLISH, "/proc/%d/cgroup", pid));
- }
-
- /** the process' control groups */
- public final ArrayList groups;
-
- private Cgroup(String path) throws IOException {
- super(path);
- String[] lines = content.split("\n");
- groups = new ArrayList<>();
- for (String line : lines) {
- try {
- groups.add(new ControlGroup(line));
- } catch (Exception ignored) {
- }
- }
- }
-
- private Cgroup(Parcel in) {
- super(in);
- this.groups = in.createTypedArrayList(ControlGroup.CREATOR);
- }
-
- public ControlGroup getGroup(String subsystem) {
- for (ControlGroup group : groups) {
- String[] systems = group.subsystems.split(",");
- for (String name : systems) {
- if (name.equals(subsystem)) {
- return group;
- }
- }
- }
- return null;
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeTypedList(groups);
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public Cgroup createFromParcel(Parcel source) {
- return new Cgroup(source);
- }
-
- @Override public Cgroup[] newArray(int size) {
- return new Cgroup[size];
- }
- };
-
-}
diff --git a/library-main/src/main/java/com/jaredrummler/android/processes/models/ControlGroup.java b/library-main/src/main/java/com/jaredrummler/android/processes/models/ControlGroup.java
deleted file mode 100644
index 7a99753..0000000
--- a/library-main/src/main/java/com/jaredrummler/android/processes/models/ControlGroup.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2015. Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import java.util.Locale;
-
-public class ControlGroup implements Parcelable {
-
- /** hierarchy ID number */
- public final int id;
-
- /** set of subsystems bound to the hierarchy */
- public final String subsystems;
-
- /** control group in the hierarchy to which the process belongs */
- public final String group;
-
- protected ControlGroup(String line) throws NumberFormatException, IndexOutOfBoundsException {
- String[] fields = line.split(":");
- id = Integer.parseInt(fields[0]);
- subsystems = fields[1];
- group = fields[2];
- }
-
- protected ControlGroup(Parcel in) {
- this.id = in.readInt();
- this.subsystems = in.readString();
- this.group = in.readString();
- }
-
- @Override public int describeContents() {
- return 0;
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(this.id);
- dest.writeString(this.subsystems);
- dest.writeString(this.group);
- }
-
- @Override public String toString() {
- return String.format(Locale.ENGLISH, "%d:%s:%s", id, subsystems, group);
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public ControlGroup createFromParcel(Parcel source) {
- return new ControlGroup(source);
- }
-
- @Override public ControlGroup[] newArray(int size) {
- return new ControlGroup[size];
- }
- };
-
-}
diff --git a/library-main/src/main/java/com/jaredrummler/android/processes/models/ProcFile.java b/library-main/src/main/java/com/jaredrummler/android/processes/models/ProcFile.java
deleted file mode 100644
index 6e12c31..0000000
--- a/library-main/src/main/java/com/jaredrummler/android/processes/models/ProcFile.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2015. Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
-public class ProcFile extends File implements Parcelable {
-
- /**
- * Read the contents of a file.
- *
- * @param path
- * the absolute path to the file.
- * @return the contents of the file.
- * @throws IOException
- * if an error occurred while reading.
- */
- static String readFile(String path) throws IOException {
- BufferedReader reader = null;
- try {
- StringBuilder output = new StringBuilder();
- reader = new BufferedReader(new FileReader(path));
- for (String line = reader.readLine(), newLine = ""; line != null; line = reader.readLine()) {
- output.append(newLine).append(line);
- newLine = "\n";
- }
- return output.toString();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException ignored) {
- }
- }
- }
- }
-
- public final String content;
-
- protected ProcFile(String path) throws IOException {
- super(path);
- content = readFile(path);
- }
-
- protected ProcFile(Parcel in) {
- super(in.readString());
- this.content = in.readString();
- }
-
- @Override public long length() {
- return content.length();
- }
-
- @Override public int describeContents() {
- return 0;
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(getAbsolutePath());
- dest.writeString(this.content);
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public ProcFile createFromParcel(Parcel in) {
- return new ProcFile(in);
- }
-
- @Override public ProcFile[] newArray(int size) {
- return new ProcFile[size];
- }
- };
-
-}
diff --git a/library-main/src/main/java/com/jaredrummler/android/processes/models/Stat.java b/library-main/src/main/java/com/jaredrummler/android/processes/models/Stat.java
deleted file mode 100644
index 07eeaae..0000000
--- a/library-main/src/main/java/com/jaredrummler/android/processes/models/Stat.java
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * Copyright (C) 2015. Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import java.io.IOException;
-import java.util.Locale;
-
-/**
- * /proc/[pid]/stat
- *
- * Status information about the process. This is used by ps(1). It is defined in the kernel
- * source file fs/proc/array.c.
- *
- * The fields, in order, with their proper scanf(3) format specifiers, are:
- *
- *
- * - pid %d The process ID.
- * - comm %s The filename of the executable, in parentheses. This is visible whether or not
- * the executable is swapped out.
- * - state %c One of the following characters, indicating process state:
- *
- * - R Running
- * - S Sleeping in an interruptible wait
- * - D Waiting in uninterruptible disk sleep
- * - Z Zombie
- * - T Stopped (on a signal) or (before Linux 2.6.33) trace stopped
- * - t Tracing stop (Linux 2.6.33 onward)
- * - W Paging (only before Linux 2.6.0)
- * - X Dead (from Linux 2.6.0 onward)
- * - x Dead (Linux 2.6.33 to 3.13 only)
- * - K Wakekill (Linux 2.6.33 to 3.13 only)
- * - W Waking (Linux 2.6.33 to 3.13 only)
- * - P Parked (Linux 3.9 to 3.13 only)
- *
- *
- * - ppid %d The PID of the parent of this process.
- * - pgrp %d The process group ID of the process.
- * - session %d The session ID of the process.
- * - tty_nr %d The controlling terminal of the process. (The minor device number is contained
- * in the combination of bits 31 to 20 and 7 to 0; the major device number is in bits 15 to 8.)
- *
- * - tpgid %d The ID of the foreground process group of the controlling terminal of the
- * process.
- * - flags %u The kernel flags word of the process. For bit meanings, see the PF_* defines in
- * the Linux kernel source file include/linux/sched.h. Details depend on the kernel version.
- * The format for this field was %lu before Linux 2.6.
- * - minflt %lu The number of minor faults the process has made which have not required
- * loading a memory page from disk.
- * - cminflt %lu The number of minor faults that the process's waited-for children have
- * made
- * - majflt %lu The number of major faults the process has made which have required loading a
- * memory page from disk.
- * - cmajflt %lu The number of major faults that the process's waited-for children have
- * made
- * - utime %lu Amount of time that this process has been scheduled in user mode, measured in
- * clock ticks (divide by sysconf(_SC_CLK_TCK)). This includes guest time, guest_time (time
- * spent running a virtual CPU, see below), so that applications that are not aware of the guest
- * time field do not lose that time from their calculations.
- * - stime %lu Amount of time that this process has been scheduled in kernel mode, measured
- * in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- * - cutime %ld Amount of time that this process's waited-for children have been scheduled in
- * user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)). (See also times(2).)
- * This includes guest time, cguest_time (time spent running a virtual CPU, see below).
- * - cstime %ld Amount of time that this process's waited-for children have been scheduled in
- * kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- * - priority %ld (Explanation for Linux 2.6) For processes running a real-time scheduling
- * policy (policy below; see sched_setscheduler(2)), this is the negated scheduling priority,
- * minus one; that is, a number in the range -2 to -100, corresponding to real-time priorities 1
- * to 99. For processes running under a non-real-time scheduling policy, this is the raw nice
- * value (setpriority(2)) as represented in the kernel. The kernel stores nice values as numbers
- * in the range 0 (high) to 39 (low), corresponding to the user-visible nice range of -20 to 19.
- * Before Linux 2.6, this was a scaled value based on the scheduler weighting given to this
- * process
- * - nice %ld The nice value (see setpriority(2)), a value in the range 19 (low priority) to
- * -20 (high priority).
- * - num_threads %ld Number of threads in this process (since Linux 2.6). Before kernel 2.6,
- * this field was hard coded to 0 as a placeholder for an earlier removed field.
- * - itrealvalue %ld The time in jiffies before the next SIGALRM is sent to the process due
- * to an interval timer. Since kernel 2.6.17, this field is no longer maintained, and is hard
- * coded as 0.
- * - starttime %llu The time the process started after system boot. In kernels before Linux
- * 2.6, this value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock
- * ticks (divide by sysconf(_SC_CLK_TCK)).
- * - The format for this field was %lu before Linux 2.6. (23) vsize %lu Virtual memory size
- * in bytes.
- * - rss %ld Resident Set Size: number of pages the process has in real memory. This is just
- * the pages which count toward text, data, or stack space. This does not include pages which
- * have not been demand-loaded in, or which are swapped out.
- * - rsslim %lu Current soft limit in bytes on the rss of the process; see the description of
- * RLIMIT_RSS in getrlimit(2).
- * - startcode %lu The address above which program text can run.
- * - endcode %lu The address below which program text can run.
- * - startstack %lu The address of the start (i.e., bottom) of the stack.
- * - kstkesp %lu The current value of ESP (stack pointer), as found in the kernel stack page
- * for the process.
- * - kstkeip %lu The current EIP (instruction pointer).
- * - signal %lu The bitmap of pending signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead
- * - blocked %lu The bitmap of blocked signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead
- * - sigignore %lu The bitmap of ignored signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead
- * - sigcatch %lu The bitmap of caught signals, displayed as a decimal number. Obsolete,
- * because it does not provide information on real-time signals; use /proc/[pid]/status
- * instead.
- * - wchan %lu This is the "channel" in which the process is waiting. It is the address of a
- * location in the kernel where the process is sleeping. The corresponding symbolic name can be
- * found in /proc/[pid]/wchan.
- * - nswap %lu Number of pages swapped (not maintained).
- * - cnswap %lu Cumulative nswap for child processes (not maintained).
- * - exit_signal %d (since Linux 2.1.22) Signal to be sent to parent when we die.
- * - processor %d (since Linux 2.2.8) CPU number last executed on.
- * - rt_priority %u (since Linux 2.5.19) Real-time scheduling priority, a number in the
- * range 1 to 99 for processes scheduled under a real-time policy, or 0, for non-real-time
- * processes (see sched_setscheduler(2)).
- * - policy %u (since Linux 2.5.19) Scheduling policy (see sched_setscheduler(2)). Decode
- * using the SCHED_* constants in linux/sched.h. The format for this field was %lu before Linux
- * 2.6.22.
- * - delayacct_blkio_ticks %llu (since Linux 2.6.18) Aggregated block I/O delays, measured
- * in clock ticks (centiseconds).
- * - guest_time %lu (since Linux 2.6.24) Guest time of the process (time spent running a
- * virtual CPU for a guest operating system), measured in clock ticks (divide by
- * sysconf(_SC_CLK_TCK)).
- * - cguest_time %ld (since Linux 2.6.24) Guest time of the process's children, measured in
- * clock ticks (divide by sysconf(_SC_CLK_TCK)).
- * - start_data %lu (since Linux 3.3) Address above which program initialized and
- * uninitialized (BSS) data are placed.
- * - end_data %lu (since Linux 3.3) Address below which program initialized and
- * uninitialized (BSS) data are placed.
- * - start_brk %lu (since Linux 3.3) Address above which program heap can be expanded with
- * brk(2).
- * - arg_start %lu (since Linux 3.5) Address above which program command-line arguments
- * (argv) are placed.
- * - arg_end %lu (since Linux 3.5) Address below program command-line arguments (argv) are
- * placed.
- * - env_start %lu (since Linux 3.5) Address above which program environment is placed.
- * - env_end %lu (since Linux 3.5) Address below which program environment is placed.
- * - exit_code %d (since Linux 3.5) The thread's exit status in the form reported by
- * waitpid(2).
- *
- */
-public final class Stat extends ProcFile {
-
- /**
- * Read /proc/[pid]/stat.
- *
- * @param pid
- * the process id.
- * @return the {@link Stat}
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public static Stat get(int pid) throws IOException {
- return new Stat(String.format(Locale.ENGLISH, "/proc/%d/stat", pid));
- }
-
- private final String[] fields;
-
- private Stat(String path) throws IOException {
- super(path);
- fields = content.split("\\s+");
- }
-
- private Stat(Parcel in) {
- super(in);
- this.fields = in.createStringArray();
- }
-
- /** The process ID. */
- public int getPid() {
- return Integer.parseInt(fields[0]);
- }
-
- /**
- * The filename of the executable, in parentheses. This is visible whether or not the
- * executable is swapped out.
- */
- public String getComm() {
- return fields[1].replace("(", "").replace(")", "");
- }
-
- /**
- * One of the following characters, indicating process state:
- *
- *
- * - 'R' Running
- * - 'S' Sleeping in an interruptible wait
- * - 'D' Waiting in uninterruptible disk sleep
- * - 'Z' Zombie
- * - 'T' Stopped (on a signal) or (before Linux 2.6.33) trace stopped
- * - 't' Tracing stop (Linux 2.6.33 onward)
- * - 'W' Paging (only before Linux 2.6.0)
- * - 'X' Dead (from Linux 2.6.0 onward)
- * - 'x' Dead (Linux 2.6.33 to 3.13 only)
- * - 'K' Wakekill (Linux 2.6.33 to 3.13 only)
- * - 'W' Waking (Linux 2.6.33 to 3.13 only)
- * - 'P' Parked (Linux 3.9 to 3.13 only)
- *
- */
- public char state() {
- return fields[2].charAt(0);
- }
-
- /**
- * The PID of the parent of this process.
- */
- public int ppid() {
- return Integer.parseInt(fields[3]);
- }
-
- /**
- * The process group ID of the process.
- */
- public int pgrp() {
- return Integer.parseInt(fields[4]);
- }
-
- /**
- * The session ID of the process.
- */
- public int session() {
- return Integer.parseInt(fields[5]);
- }
-
- /**
- * The controlling terminal of the process. (The minor device number is contained in the
- * combination of bits 31 to 20 and 7 to 0; the major device number is in bits 15 to 8.)
- */
- public int tty_nr() {
- return Integer.parseInt(fields[6]);
- }
-
- /**
- * The ID of the foreground process group of the controlling terminal of the process.
- */
- public int tpgid() {
- return Integer.parseInt(fields[7]);
- }
-
- /**
- * The kernel flags word of the process. For bit meanings, see the PF_* defines in the Linux
- * kernel source file include/linux/sched.h. Details depend on the kernel version.
- *
- * The format for this field was %lu before Linux 2.6.
- */
- public int flags() {
- return Integer.parseInt(fields[8]);
- }
-
- /**
- * The number of minor faults the process has made which have not required loading a memory
- * page from disk.
- */
- public long minflt() {
- return Long.parseLong(fields[9]);
- }
-
- /**
- * The number of minor faults that the process's waited-for children have made.
- */
- public long cminflt() {
- return Long.parseLong(fields[10]);
- }
-
- /**
- * The number of major faults the process has made which have required loading a memory page
- * from disk.
- */
- public long majflt() {
- return Long.parseLong(fields[11]);
- }
-
- /**
- * The number of major faults that the process's waited-for children have made.
- */
- public long cmajflt() {
- return Long.parseLong(fields[12]);
- }
-
- /**
- * Amount of time that this process has been scheduled in user mode, measured in clock ticks
- * (divide by sysconf(_SC_CLK_TCK)). This includes guest time, guest_time (time spent running
- * a virtual CPU, see below), so that applications that are not aware of the guest time field
- * do not lose that time from their calculations.
- */
- public long utime() {
- return Long.parseLong(fields[13]);
- }
-
- /**
- * Amount of time that this process has been scheduled in kernel mode, measured in clock ticks
- * (divide by sysconf(_SC_CLK_TCK)).
- */
- public long stime() {
- return Long.parseLong(fields[14]);
- }
-
- /**
- * Amount of time that this process's waited-for children have been scheduled in user mode,
- * measured in clock ticks (divide by sysconf(_SC_CLK_TCK)). (See also times(2).) This
- * includes guest time, cguest_time (time spent running a virtual CPU, see below).
- */
- public long cutime() {
- return Long.parseLong(fields[15]);
- }
-
- /**
- * Amount of time that this process's waited-for children have been scheduled in kernel mode,
- * measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- */
- public long cstime() {
- return Long.parseLong(fields[16]);
- }
-
- /**
- * (Explanation for Linux 2.6) For processes running a real-time scheduling policy (policy
- * below; see sched_setscheduler(2)), this is the negated scheduling priority, minus one; that
- * is,
- * a number in the range -2 to -100, corresponding to real-time priorities 1 to 99. For
- * processes
- * running under a non-real-time scheduling policy, this is the raw nice value (setpriority(2))
- * as
- * represented in the kernel. The kernel stores nice values as numbers in the range 0 (high) to
- * 39 (low), corresponding to the user-visible nice range of -20 to 19.
- *
- * Before Linux 2.6, this was a scaled value based on the scheduler weighting given to this
- * process.
- */
- public long priority() {
- return Long.parseLong(fields[17]);
- }
-
- /**
- * The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high
- * priority).
- */
- public int nice() {
- return Integer.parseInt(fields[18]);
- }
-
- /**
- * Number of threads in this process (since Linux 2.6). Before kernel 2.6, this field was hard
- * coded to 0 as a placeholder for an earlier removed field.
- */
- public long num_threads() {
- return Long.parseLong(fields[19]);
- }
-
- /**
- * The time in jiffies before the next SIGALRM is sent to the process due to an interval timer.
- * Since kernel 2.6.17, this field is no longer maintained, and is hard coded as 0.
- */
- public long itrealvalue() {
- return Long.parseLong(fields[20]);
- }
-
- /**
- * The time the process started after system boot. In kernels before Linux 2.6, this value was
- * expressed in jiffies. Since Linux 2.6, the value is expressed in clock ticks (divide by
- * sysconf(_SC_CLK_TCK)).
- *
- * The format for this field was %lu before Linux 2.6.
- */
- public long starttime() {
- return Long.parseLong(fields[21]);
- }
-
- /**
- * Virtual memory size in bytes.
- */
- public long vsize() {
- return Long.parseLong(fields[22]);
- }
-
- /**
- * Resident Set Size: number of pages the process has in real memory. This is just the pages
- * which count toward text, data, or stack space. This does not include pages which have not
- * been demand-loaded in, or which are swapped out.
- */
- public long rss() {
- return Long.parseLong(fields[23]);
- }
-
- /**
- * Current soft limit in bytes on the rss of the process; see the description of RLIMIT_RSS in
- * getrlimit(2).
- */
- public long rsslim() {
- return Long.parseLong(fields[24]);
- }
-
- /**
- * The address above which program text can run.
- */
- public long startcode() {
- return Long.parseLong(fields[25]);
- }
-
- /**
- * The address below which program text can run.
- */
- public long endcode() {
- return Long.parseLong(fields[26]);
- }
-
- /**
- * The address of the start (i.e., bottom) of the stack.
- */
- public long startstack() {
- return Long.parseLong(fields[27]);
- }
-
- /**
- * The current value of ESP (stack pointer), as found in the kernel stack page for the process.
- */
- public long kstkesp() {
- return Long.parseLong(fields[28]);
- }
-
- /**
- * The current EIP (instruction pointer).
- */
- public long kstkeip() {
- return Long.parseLong(fields[29]);
- }
-
- /**
- * The bitmap of pending signals, displayed as a decimal number. Obsolete, because it does not
- * provide information on real-time signals; use /proc/[pid]/status instead.
- */
- public long signal() {
- return Long.parseLong(fields[30]);
- }
-
- /**
- * The bitmap of blocked signals, displayed as a decimal number. Obsolete, because it does not
- * provide information on real-time signals; use /proc/[pid]/status instead.
- */
- public long blocked() {
- return Long.parseLong(fields[31]);
- }
-
- /**
- * The bitmap of ignored signals, displayed as a decimal number. Obsolete, because it does not
- * provide information on real-time signals; use /proc/[pid]/status instead.
- */
- public long sigignore() {
- return Long.parseLong(fields[32]);
- }
-
- /**
- * The bitmap of caught signals, displayed as a decimal number. Obsolete, because it does not
- * provide information on real-time signals; use /proc/[pid]/status instead.
- */
- public long sigcatch() {
- return Long.parseLong(fields[33]);
- }
-
- /**
- * This is the "channel" in which the process is waiting. It is the address of a location in the
- * kernel where the process is sleeping. The corresponding symbolic name can be found in
- * /proc/[pid]/wchan.
- */
- public long wchan() {
- return Long.parseLong(fields[34]);
- }
-
- /**
- * Number of pages swapped (not maintained).
- */
- public long nswap() {
- return Long.parseLong(fields[35]);
- }
-
- /**
- * Cumulative nswap for child processes (not maintained).
- */
- public long cnswap() {
- return Long.parseLong(fields[36]);
- }
-
- /**
- * (since Linux 2.1.22)
- * Signal to be sent to parent when we die.
- */
- public int exit_signal() {
- return Integer.parseInt(fields[37]);
- }
-
- /**
- * (since Linux 2.2.8)
- * CPU number last executed on.
- */
- public int processor() {
- return Integer.parseInt(fields[38]);
- }
-
- /**
- * (since Linux 2.5.19)
- * Real-time scheduling priority, a number in the range 1 to 99 for processes scheduled under a
- * real-time policy, or 0, for non-real-time processes (see sched_setscheduler(2)).
- */
- public int rt_priority() {
- return Integer.parseInt(fields[39]);
- }
-
- /**
- * (since Linux 2.5.19) Scheduling policy (see sched_setscheduler(2)). Decode using the
- * SCHED_*
- * constants in linux/sched.h.
- *
- * The format for this field was %lu before Linux 2.6.22.
- */
- public int policy() {
- return Integer.parseInt(fields[40]);
- }
-
- /**
- * (since Linux 2.6.18)
- * Aggregated block I/O delays, measured in clock ticks (centiseconds).
- */
- public long delayacct_blkio_ticks() {
- return Long.parseLong(fields[41]);
- }
-
- /**
- * (since Linux 2.6.24)
- * Guest time of the process (time spent running a virtual CPU for a guest operating system),
- * measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
- */
- public long guest_time() {
- return Long.parseLong(fields[42]);
- }
-
- /**
- * (since Linux 2.6.24)
- * Guest time of the process's children, measured in clock ticks (divide by
- * sysconf(_SC_CLK_TCK)).
- */
- public long cguest_time() {
- return Long.parseLong(fields[43]);
- }
-
- /**
- * (since Linux 3.3)
- * Address above which program initialized and uninitialized (BSS) data are placed.
- */
- public long start_data() {
- return Long.parseLong(fields[44]);
- }
-
- /**
- * (since Linux 3.3)
- * Address below which program initialized and uninitialized (BSS) data are placed.
- */
- public long end_data() {
- return Long.parseLong(fields[45]);
- }
-
- /**
- * (since Linux 3.3)
- * Address above which program heap can be expanded with brk(2).
- */
- public long start_brk() {
- return Long.parseLong(fields[46]);
- }
-
- /**
- * (since Linux 3.5)
- * Address above which program command-line arguments (argv) are placed.
- */
- public long arg_start() {
- return Long.parseLong(fields[47]);
- }
-
- /**
- * (since Linux 3.5)
- * Address below program command-line arguments (argv) are placed.
- */
- public long arg_end() {
- return Long.parseLong(fields[48]);
- }
-
- /**
- * (since Linux 3.5)
- * Address above which program environment is placed.
- */
- public long env_start() {
- return Long.parseLong(fields[49]);
- }
-
- /**
- * (since Linux 3.5)
- * Address below which program environment is placed.
- */
- public long env_end() {
- return Long.parseLong(fields[50]);
- }
-
- /**
- * (since Linux 3.5)
- * The thread's exit status in the form reported by waitpid(2).
- */
- public int exit_code() {
- return Integer.parseInt(fields[51]);
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeStringArray(fields);
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public Stat createFromParcel(Parcel source) {
- return new Stat(source);
- }
-
- @Override public Stat[] newArray(int size) {
- return new Stat[size];
- }
- };
-
-}
diff --git a/library-main/src/main/java/com/jaredrummler/android/processes/models/Statm.java b/library-main/src/main/java/com/jaredrummler/android/processes/models/Statm.java
deleted file mode 100644
index 6f9f9b9..0000000
--- a/library-main/src/main/java/com/jaredrummler/android/processes/models/Statm.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2015. Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import java.io.IOException;
-import java.util.Locale;
-
-/**
- * Provides information about memory usage, measured in pages.
- *
- * The columns are:
- *
- *
- * - size (1) total program size (same as VmSize in /proc/[pid]/status)
- * - resident (2) resident set size (same as VmRSS in /proc/[pid]/status)
- * - share (3) shared pages (i.e., backed by a file)
- * - text (4) text (code)
- * - lib (5) library (unused in Linux 2.6)
- * - data (6) data + stack
- * - dt (7) dirty pages (unused in Linux 2.6)
- *
- */
-public final class Statm extends ProcFile {
-
- /**
- * Read /proc/[pid]/statm.
- *
- * @param pid
- * the process id.
- * @return the {@link Statm}
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public static Statm get(int pid) throws IOException {
- return new Statm(String.format(Locale.ENGLISH, "/proc/%d/statm", pid));
- }
-
- public final String[] fields;
-
- private Statm(String path) throws IOException {
- super(path);
- fields = content.split("\\s+");
- }
-
- private Statm(Parcel in) {
- super(in);
- this.fields = in.createStringArray();
- }
-
- /**
- * @return the total program size in bytes
- */
- public long getSize() {
- return Long.parseLong(fields[0]) * 1024;
- }
-
- /**
- * @return the resident set size in bytes
- */
- public long getResidentSetSize() {
- return Long.parseLong(fields[1]) * 1024;
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeStringArray(this.fields);
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public Statm createFromParcel(Parcel source) {
- return new Statm(source);
- }
-
- @Override public Statm[] newArray(int size) {
- return new Statm[size];
- }
- };
-
-}
diff --git a/library-main/src/main/java/com/jaredrummler/android/processes/models/Status.java b/library-main/src/main/java/com/jaredrummler/android/processes/models/Status.java
deleted file mode 100644
index f150525..0000000
--- a/library-main/src/main/java/com/jaredrummler/android/processes/models/Status.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2015. Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.jaredrummler.android.processes.models;
-
-import android.os.Parcel;
-import java.io.IOException;
-import java.util.Locale;
-
-/**
- * /proc/[pid]/status
- *
- * Provides much of the information in /proc/[pid]/stat and /proc/[pid]/statm in a format that's
- * easier for humans to parse.
- *
- * Here's an example:
- *
- *
- * $ cat /proc/$$/status
- * Name: bash
- * State: S (sleeping)
- * Tgid: 3515
- * Pid: 3515
- * PPid: 3452
- * TracerPid: 0
- * Uid: 1000 1000 1000 1000
- * Gid: 100 100 100 100
- * FDSize: 256
- * Groups: 16 33 100
- * VmPeak: 9136 kB
- * VmSize: 7896 kB
- * VmLck: 0 kB
- * VmPin: 0 kB
- * VmHWM: 7572 kB
- * VmRSS: 6316 kB
- * VmData: 5224 kB
- * VmStk: 88 kB
- * VmExe: 572 kB
- * VmLib: 1708 kB
- * VmPMD: 4 kB
- * VmPTE: 20 kB
- * VmSwap: 0 kB
- * Threads: 1
- * SigQ: 0/3067
- * SigPnd: 0000000000000000
- * ShdPnd: 0000000000000000
- * SigBlk: 0000000000010000
- * SigIgn: 0000000000384004
- * SigCgt: 000000004b813efb
- * CapInh: 0000000000000000
- * CapPrm: 0000000000000000
- * CapEff: 0000000000000000
- * CapBnd: ffffffffffffffff
- * Seccomp: 0
- * Cpus_allowed: 00000001
- * Cpus_allowed_list: 0
- * Mems_allowed: 1
- * Mems_allowed_list: 0
- * voluntary_ctxt_switches: 150
- * nonvoluntary_ctxt_switches: 545
- *
- *
- * The fields are as follows:
- *
- *
- * - Name: Command run by this process.
- * - State: Current state of the process. One of "R (running)", "S (sleeping)", "D (disk
- * sleep)",
- * "T (stopped)", "T (tracing stop)", "Z (zombie)", or "X (dead)".
- * - Tgid: Thread group ID (i.e., Process ID).
- * - Pid: Thread ID (see gettid(2)).
- * - PPid: PID of parent process.
- * - TracerPid: PID of process tracing this process (0 if not being traced).
- * - Uid, Gid: Real, effective, saved set, and filesystem UIDs (GIDs).
- * - FDSize: Number of file descriptor slots currently allocated.
- * - Groups: Supplementary group list.
- * - VmPeak: Peak virtual memory size.
- * - VmSize: Virtual memory size.
- * - VmLck: Locked memory size (see mlock(3)).
- * - VmPin: Pinned memory size (since Linux 3.2). These are pages that can't be moved because
- * something needs to directly access physical memory.
- * - VmHWM: Peak resident set size ("high water mark").
- * - VmRSS: Resident set size.
- * - VmData, VmStk, VmExe: Size of data, stack, and text segments.
- * - VmLib: Shared library code size.
- * - VmPTE: Page table entries size (since Linux 2.6.10).
- * - VmPMD: Size of second-level page tables (since Linux 4.0).
- * - VmSwap: Swapped-out virtual memory size by anonymous private pages; shmem swap usage is not
- * included (since Linux 2.6.34).
- * - Threads: Number of threads in process containing this thread.
- * - SigQ: This field contains two slash-separated numbers that relate to queued signals for the
- * real user ID of this process. The first of these is the number of currently queued signals for
- * this real user ID, and the second is the resource limit on the number of queued signals for this
- * process (see the description of RLIMIT_SIGPENDING in getrlimit(2)).
- * - SigPnd, ShdPnd: Number of signals pending for thread and for process as a whole (see
- * pthreads(7) and signal(7)).
- * - SigBlk, SigIgn, SigCgt: Masks indicating signals being blocked, ignored, and caught (see
- * signal(7)).
- * - CapInh, CapPrm, CapEff: Masks of capabilities enabled in inheritable, permitted, and
- * effective sets (see capabilities(7)).
- * - CapBnd: Capability Bounding set (since Linux 2.6.26, see capabilities(7)).
- * - Seccomp: Seccomp mode of the process (since Linux 3.8, see seccomp(2)). 0 means
- * SECCOMP_MODE_DISABLED; 1 means SECCOMP_MODE_STRICT; 2 means SECCOMP_MODE_FILTER. This field is
- * provided only if the kernel was built with the CONFIG_SECCOMP kernel configuration option
- * enabled.
- * - Cpus_allowed: Mask of CPUs on which this process may run (since Linux 2.6.24, see
- * cpuset(7)).
- * - Cpus_allowed_list: Same as previous, but in "list format" (since Linux 2.6.26, see
- * cpuset(7)).
- * - Mems_allowed: Mask of memory nodes allowed to this process (since Linux 2.6.24, see
- * cpuset(7)).
- * - Mems_allowed_list: Same as previous, but in "list format" (since Linux 2.6.26, see
- * cpuset(7)).
- * voluntary_ctxt_switches, nonvoluntary_ctxt_switches: Number of voluntary and involuntary context
- * switches (since Linux 2.6.23).
- *
- */
-public final class Status extends ProcFile {
-
- /**
- * Read /proc/[pid]/status.
- *
- * @param pid
- * the process id.
- * @return the {@link Status}
- * @throws IOException
- * if the file does not exist or we don't have read permissions.
- */
- public static Status get(int pid) throws IOException {
- return new Status(String.format(Locale.ENGLISH, "/proc/%d/status", pid));
- }
-
- private Status(String path) throws IOException {
- super(path);
- }
-
- private Status(Parcel in) {
- super(in);
- }
-
- /**
- * Get the value of one of the fields.
- *
- * @param fieldName
- * the field name. E.g "PPid", "Uid", "Groups".
- * @return The value of the field or {@code null}.
- */
- public String getValue(String fieldName) {
- String[] lines = content.split("\n");
- for (String line : lines) {
- if (line.startsWith(fieldName + ":")) {
- return line.split(fieldName + ":")[1].trim();
- }
- }
- return null;
- }
-
- /**
- * @return The process' UID or -1 if parsing the UID failed.
- */
- public int getUid() {
- try {
- return Integer.parseInt(getValue("Uid").split("\\s+")[0]);
- } catch (Exception e) {
- return -1;
- }
- }
-
- /**
- * @return The process' GID or -1 if parsing the GID failed.
- */
- public int getGid() {
- try {
- return Integer.parseInt(getValue("Gid").split("\\s+")[0]);
- } catch (Exception e) {
- return -1;
- }
- }
-
- public static final Creator CREATOR = new Creator() {
-
- @Override public Status createFromParcel(Parcel source) {
- return new Status(source);
- }
-
- @Override public Status[] newArray(int size) {
- return new Status[size];
- }
- };
-
-}
diff --git a/library-sups/.gitignore b/library-sups/.gitignore
deleted file mode 100644
index d0b97c6..0000000
--- a/library-sups/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/build
-*.iml
\ No newline at end of file
diff --git a/library-main/.gitignore b/library/.gitignore
similarity index 100%
rename from library-main/.gitignore
rename to library/.gitignore
diff --git a/library-sups/build.gradle b/library/build.gradle
similarity index 100%
rename from library-sups/build.gradle
rename to library/build.gradle
diff --git a/library-sups/gradle.properties b/library/gradle.properties
similarity index 95%
rename from library-sups/gradle.properties
rename to library/gradle.properties
index 1ec5c19..9a623cb 100644
--- a/library-sups/gradle.properties
+++ b/library/gradle.properties
@@ -1,5 +1,5 @@
-VERSION_NAME=0.0.1
-VERSION_CODE=1
+VERSION_NAME=0.0.2
+VERSION_CODE=2
GROUP=com.jaredrummler
POM_NAME=Android Processes
diff --git a/library-sups/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
similarity index 100%
rename from library-sups/src/main/AndroidManifest.xml
rename to library/src/main/AndroidManifest.xml
diff --git a/library-sups/src/main/java/com/jaredrummler/android/sups/LineParseError.java b/library/src/main/java/com/jaredrummler/android/sups/LineParseError.java
similarity index 100%
rename from library-sups/src/main/java/com/jaredrummler/android/sups/LineParseError.java
rename to library/src/main/java/com/jaredrummler/android/sups/LineParseError.java
diff --git a/library-sups/src/main/java/com/jaredrummler/android/sups/ProcessStatusInfo.java b/library/src/main/java/com/jaredrummler/android/sups/ProcessStatusInfo.java
similarity index 90%
rename from library-sups/src/main/java/com/jaredrummler/android/sups/ProcessStatusInfo.java
rename to library/src/main/java/com/jaredrummler/android/sups/ProcessStatusInfo.java
index d208c18..c7ef064 100644
--- a/library-sups/src/main/java/com/jaredrummler/android/sups/ProcessStatusInfo.java
+++ b/library/src/main/java/com/jaredrummler/android/sups/ProcessStatusInfo.java
@@ -29,6 +29,8 @@ public class ProcessStatusInfo implements Parcelable {
private static final Pattern PS_LINE_PATTERN = Pattern.compile(
"^(\\S+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(-?\\d+)\\s+(-?\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(bg|fg|un|er)?\\s+(\\S+)\\s+(\\S+)\\s+(D|R|S|T|W|X|Z)\\s+(\\S+)\\s+\\(u:(\\d+),\\s+s:(\\d+)\\)$");
+ private static final Pattern PROCESS_NAME_PATTERN = Pattern.compile(
+ "^([A-Za-z]{1}[A-Za-z0-9_]*[\\.|:])*[A-Za-z][A-Za-z0-9_]*$");
private static final Pattern MULTI_USER_APP_ID = Pattern.compile("^u\\d+_a\\d+$");
private static final Pattern DEPRECATED_APP_ID = Pattern.compile("^app_\\d+$");
@@ -74,20 +76,20 @@ public class ProcessStatusInfo implements Parcelable {
/**
* Possible states:
- *
- * "D" uninterruptible sleep (usually IO)
- *
- * "R" running or runnable (on run queue)
- *
- * "S" interruptible sleep (waiting for an event to complete)
- *
- * "T" stopped, either by a job control signal or because it is being traced
- *
- * "W" paging (not valid since the 2.6.xx kernel)
- *
- * "X" dead (should never be seen)
- *
- * "Z" defunct ("zombie") process, terminated but not reaped by its parent
+ *
+ * "D" uninterruptible sleep (usually IO)
+ *
+ * "R" running or runnable (on run queue)
+ *
+ * "S" interruptible sleep (waiting for an event to complete)
+ *
+ * "T" stopped, either by a job control signal or because it is being traced
+ *
+ * "W" paging (not valid since the 2.6.xx kernel)
+ *
+ * "X" dead (should never be seen)
+ *
+ * "Z" defunct ("zombie") process, terminated but not reaped by its parent
*/
public final String state;
@@ -130,6 +132,9 @@ public class ProcessStatusInfo implements Parcelable {
}
public boolean isApp() {
+ if (!PROCESS_NAME_PATTERN.matcher(name).matches()) {
+ return false;
+ }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// u{user_id}_a{app_id} is used on API 17+ for multiple user account support.
return MULTI_USER_APP_ID.matcher(user).matches();
diff --git a/library-sups/src/main/java/com/jaredrummler/android/sups/ps.java b/library/src/main/java/com/jaredrummler/android/sups/ps.java
similarity index 100%
rename from library-sups/src/main/java/com/jaredrummler/android/sups/ps.java
rename to library/src/main/java/com/jaredrummler/android/sups/ps.java
diff --git a/settings.gradle b/settings.gradle
index 1ad6fbc..462ba77 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':library-main', ':demo', ':library-sups'
+include ':demo', ':library'