กระบวนการยูทิลิตี้

public final class ProcessUtil
extends Object

java.lang.Object
com.android.sts.common.ProcessUtil


ตัวช่วยต่างๆ ในการค้นหา รอ และฆ่ากระบวนการบนอุปกรณ์

สรุป

คลาสที่ซ้อนกัน

class ProcessUtil.KillException

ค่าคงที่

long PROCESS_POLL_PERIOD_MS

long PROCESS_WAIT_TIMEOUT_MS

วิธีการสาธารณะ

static Optional<IFileEntry> findFileLoadedByProcess (ITestDevice device, String process, String filenameSubstr)

ส่งคืนรายการไฟล์ของไฟล์แรกที่โหลดโดยกระบวนการที่ระบุพร้อมชื่อที่ระบุ

static Optional<List<String>> findFilesLoadedByProcess (ITestDevice device, int pid, Pattern filePattern)

ส่งคืนชื่อไฟล์ของไฟล์ที่ระบุ ซึ่งโหลดโดยกระบวนการที่ระบุ

static Optional<String> getProcessName (ITestDevice device, int pid)

รับเนื้อหาจาก /proc/pid/cmdline

static boolean killAll (ITestDevice device, String pgrepRegex, long timeoutMs, boolean expectExist)

ส่ง SIGKILL ไปยังกระบวนการทั้งหมดที่ตรงกับรูปแบบ

static boolean killAll (ITestDevice device, String pgrepRegex, long timeoutMs)

ส่ง SIGKILL ไปยังกระบวนการทั้งหมดที่ตรงกับรูปแบบ

static void killPid (ITestDevice device, int pid, long timeoutMs)

ส่ง SIGKILL ไปที่กระบวนการและรอให้ออก

static void killPid (ITestDevice device, int pid, int signal, long timeoutMs)

ส่งสัญญาณไปยังกระบวนการและรอให้ออกจากกระบวนการ

static Optional<List<String>> listOpenFiles (ITestDevice device, int pid)

ส่งกลับชื่อไฟล์ที่เปิดอยู่ในปัจจุบันของกระบวนการที่ระบุ

static Optional<Integer> pidOf (ITestDevice device, String pgrepRegex)

รับ pid เดียวที่ตรงกับรูปแบบที่ส่งไปยัง `pgrep`

static Optional<Map<Integer, String>> pidsOf (ITestDevice device, String pgrepRegex)

รับ pids ที่ตรงกับรูปแบบที่ส่งไปยัง `pgrep`

static void waitPidExited (ITestDevice device, int pid)

รอให้กระบวนการออกจากการทำงาน

static void waitPidExited (ITestDevice device, int pid, long timeoutMs)

รอให้กระบวนการออกจากการทำงาน

static Map<Integer, String> waitProcessRunning (ITestDevice device, String pgrepRegex, long timeoutMs)

รอจนกว่าจะพบกระบวนการที่ทำงานอยู่สำหรับ regex ที่ระบุ

static Map<Integer, String> waitProcessRunning (ITestDevice device, String pgrepRegex)

รอจนกว่าจะพบกระบวนการที่ทำงานอยู่สำหรับ regex ที่กำหนด

static AutoCloseable withProcessKill (ITestDevice device, String pgrepRegex, Runnable beforeCloseKill, long timeoutMs)

ฆ่ากระบวนการที่จุดเริ่มต้นและจุดสิ้นสุดของการทดสอบ

static AutoCloseable withProcessKill (ITestDevice device, String pgrepRegex, Runnable beforeCloseKill)

ฆ่ากระบวนการที่จุดเริ่มต้นและจุดสิ้นสุดของการทดสอบ

ค่าคงที่

PROCESS_POLL_PERIOD_MS

public static final long PROCESS_POLL_PERIOD_MS

ค่าคงที่: 250 (0x00000000000000fa)

PROCESS_WAIT_TIMEOUT_MS

public static final long PROCESS_WAIT_TIMEOUT_MS

ค่าคงที่: 10,000 (0x0000000000002710)

วิธีการสาธารณะ

ค้นหา FileLoaddByProcess

public static Optional<IFileEntry> findFileLoadedByProcess (ITestDevice device, 
                String process, 
                String filenameSubstr)

ส่งคืนรายการไฟล์ของไฟล์แรกที่โหลดโดยกระบวนการที่ระบุพร้อมชื่อที่ระบุ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้งาน

process String : รูปแบบ pgrep ของกระบวนการที่จะค้นหา

filenameSubstr String : ส่วนหนึ่งของชื่อไฟล์/พาธที่โหลดโดยกระบวนการ

การส่งคืน
Optional<IFileEntry> ตัวเลือกของ IFileEntry ของเส้นทางของไฟล์บนอุปกรณ์หากมีอยู่

ขว้าง
DeviceNotAvailableException

ค้นหาไฟล์ LoadedByProcess

public static Optional<List<String>> findFilesLoadedByProcess (ITestDevice device, 
                int pid, 
                Pattern filePattern)

ส่งคืนชื่อไฟล์ของไฟล์ที่ระบุ ซึ่งโหลดโดยกระบวนการที่ระบุ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้งาน

pid int : id ของกระบวนการที่จะค้นหา

filePattern Pattern : รูปแบบของชื่อไฟล์ที่จะส่งคืน

การส่งคืน
Optional<List<String>> ตัวเลือกของไฟล์ที่กรอง ว่างเปล่าหากไม่พบกระบวนการหรือไม่สามารถอ่านไฟล์ที่เปิดได้

ขว้าง
DeviceNotAvailableException

รับชื่อกระบวนการ

public static Optional<String> getProcessName (ITestDevice device, 
                int pid)

รับเนื้อหาจาก /proc/pid/cmdline

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pid int : id ของกระบวนการเพื่อรับชื่อ

การส่งคืน
Optional<String> สตริงทางเลือกของเนื้อหาของ /proc/pid/cmdline; ว่างเปล่าหากไม่พบ pid

ขว้าง
DeviceNotAvailableException

ฆ่าทั้งหมด

public static boolean killAll (ITestDevice device, 
                String pgrepRegex, 
                long timeoutMs, 
                boolean expectExist)

ส่ง SIGKILL ไปยังกระบวนการทั้งหมดที่ตรงกับรูปแบบ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : สตริงที่แสดงถึง regex สำหรับ pgrep

timeoutMs long : ต้องรอนานแค่ไหนก่อนที่จะโยน TimeoutException

expectExist boolean : ควรส่งข้อยกเว้นเมื่อไม่มีกระบวนการใดถูกฆ่าหรือไม่

การส่งคืน
boolean ไม่ว่ากระบวนการใดๆ จะถูกฆ่าหรือไม่

ขว้าง
DeviceNotAvailableException
TimeoutException
ProcessUtil.KillException

ฆ่าทั้งหมด

public static boolean killAll (ITestDevice device, 
                String pgrepRegex, 
                long timeoutMs)

ส่ง SIGKILL ไปยังกระบวนการทั้งหมดที่ตรงกับรูปแบบ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : สตริงที่แสดงถึง regex สำหรับ pgrep

timeoutMs long : ต้องรอนานแค่ไหนก่อนที่จะโยน TimeoutException

การส่งคืน
boolean ไม่ว่ากระบวนการใดๆ จะถูกฆ่าหรือไม่

ขว้าง
DeviceNotAvailableException
TimeoutException
ProcessUtil.KillException

คิลพิด

public static void killPid (ITestDevice device, 
                int pid, 
                long timeoutMs)

ส่ง SIGKILL ไปที่กระบวนการและรอให้ออก

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pid int : id ของกระบวนการที่จะรอจนกว่าจะออก

timeoutMs long : ต้องรอนานแค่ไหนก่อนที่จะโยน TimeoutException

ขว้าง
DeviceNotAvailableException
TimeoutException
ProcessUtil.KillException

คิลพิด

public static void killPid (ITestDevice device, 
                int pid, 
                int signal, 
                long timeoutMs)

ส่งสัญญาณไปยังกระบวนการและรอให้ออกจากกระบวนการ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pid int : id ของกระบวนการที่จะรอจนกว่าจะออก

signal int : สัญญาณที่จะส่งไปยังกระบวนการ

timeoutMs long : ต้องรอนานแค่ไหนก่อนที่จะโยน TimeoutException

ขว้าง
DeviceNotAvailableException
TimeoutException
ProcessUtil.KillException

รายการ OpenFiles

public static Optional<List<String>> listOpenFiles (ITestDevice device, 
                int pid)

ส่งกลับชื่อไฟล์ที่เปิดอยู่ในปัจจุบันของกระบวนการที่ระบุ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้งาน

pid int : id ของกระบวนการที่จะค้นหา

การส่งคืน
Optional<List<String>> ตัวเลือกของไฟล์ที่เปิดอยู่ ว่างเปล่าหากไม่พบกระบวนการหรือไม่สามารถอ่านไฟล์ที่เปิดได้

ขว้าง
DeviceNotAvailableException

pidOf

public static Optional<Integer> pidOf (ITestDevice device, 
                String pgrepRegex)

รับ pid เดียวที่ตรงกับรูปแบบที่ส่งไปยัง `pgrep` โยน IllegalArgumentException เมื่อมี PID มากกว่าหนึ่งรายการที่ตรงกับรูปแบบ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : สตริงที่แสดงถึง regex สำหรับ pgrep

การส่งคืน
Optional<Integer> จำนวนเต็มเผื่อเลือกของ pid; ว่างเปล่าหาก pgrep ไม่ส่งคืน EXIT_SUCCESS

ขว้าง
DeviceNotAvailableException
IllegalArgumentException

pidsof

public static Optional<Map<Integer, String>> pidsOf (ITestDevice device, 
                String pgrepRegex)

รับ pids ที่ตรงกับรูปแบบที่ส่งไปยัง `pgrep` เนื่องจาก /proc/pid/comm ถูกตัดทอน `pgrep` จึงถูกส่งผ่านด้วย `-f` เพื่อตรวจสอบบรรทัดคำสั่งทั้งหมด

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : สตริงที่แสดงถึง regex สำหรับ pgrep

การส่งคืน
Optional<Map<Integer, String>> แผนที่ทางเลือกของ pid ถึงบรรทัดคำสั่ง ว่างเปล่าหาก pgrep ไม่ส่งคืน EXIT_SUCCESS

ขว้าง
DeviceNotAvailableException

waitPidExited

public static void waitPidExited (ITestDevice device, 
                int pid)

รอให้กระบวนการออกจากการทำงาน สิ่งนี้ไม่ได้รอให้มันเปลี่ยนแปลง แต่เพียงแค่ไม่มีอยู่จริง เป็นไปได้แต่ไม่น่าเป็นไปได้ที่ pid จะถูกนำมาใช้ซ้ำระหว่างการสำรวจความคิดเห็น

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pid int : id ของกระบวนการที่จะรอจนกว่าจะออก

ขว้าง
TimeoutException
DeviceNotAvailableException
ProcessUtil.KillException

waitPidExited

public static void waitPidExited (ITestDevice device, 
                int pid, 
                long timeoutMs)

รอให้กระบวนการออกจากการทำงาน สิ่งนี้ไม่ได้รอให้มันเปลี่ยนแปลง แต่เพียงแค่ไม่มีอยู่จริง เป็นไปได้แต่ไม่น่าเป็นไปได้ที่ pid จะถูกนำมาใช้ซ้ำระหว่างการสำรวจความคิดเห็น

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pid int : id ของกระบวนการที่จะรอจนกว่าจะออก

timeoutMs long : ต้องรอนานแค่ไหนก่อนที่จะโยน TimeoutException

ขว้าง
TimeoutException
DeviceNotAvailableException
ProcessUtil.KillException

รอกระบวนการทำงาน

public static Map<Integer, String> waitProcessRunning (ITestDevice device, 
                String pgrepRegex, 
                long timeoutMs)

รอจนกว่าจะพบกระบวนการที่ทำงานอยู่สำหรับ regex ที่ระบุ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : สตริงที่แสดงถึง regex สำหรับ pgrep

timeoutMs long : ต้องรอนานแค่ไหนก่อนที่จะโยน TimeoutException

การส่งคืน
Map<Integer, String> pid ไปยังคำสั่ง map จาก pidsOf(...)

ขว้าง
TimeoutException
DeviceNotAvailableException

รอกระบวนการทำงาน

public static Map<Integer, String> waitProcessRunning (ITestDevice device, 
                String pgrepRegex)

รอจนกว่าจะพบกระบวนการที่ทำงานอยู่สำหรับ regex ที่ระบุ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : สตริงที่แสดงถึง regex สำหรับ pgrep

การส่งคืน
Map<Integer, String> pid ไปยังคำสั่ง map จาก pidsOf(...)

ขว้าง
TimeoutException
DeviceNotAvailableException

ด้วยProcessKill

public static AutoCloseable withProcessKill (ITestDevice device, 
                String pgrepRegex, 
                Runnable beforeCloseKill, 
                long timeoutMs)

ฆ่ากระบวนการที่จุดเริ่มต้นและจุดสิ้นสุดของการทดสอบ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : รูปแบบชื่อของกระบวนการที่จะฆ่าเพื่อมอบให้กับ pgrep

beforeCloseKill Runnable : เรียกใช้สำหรับการดำเนินการใด ๆ ที่ต้องล้างข้อมูลก่อนที่จะฆ่ากระบวนการในสภาพแวดล้อมปกติเมื่อสิ้นสุดการทดสอบ สามารถเป็นโมฆะได้

timeoutMs long : ระยะเวลาในหน่วยมิลลิวินาทีในการรอให้กระบวนการฆ่า

การส่งคืน
AutoCloseable วัตถุที่จะหยุดกระบวนการอีกครั้งเมื่อถูกปิด

ขว้าง
DeviceNotAvailableException
TimeoutException
ProcessUtil.KillException

ด้วยProcessKill

public static AutoCloseable withProcessKill (ITestDevice device, 
                String pgrepRegex, 
                Runnable beforeCloseKill)

ฆ่ากระบวนการที่จุดเริ่มต้นและจุดสิ้นสุดของการทดสอบ

พารามิเตอร์
device ITestDevice : อุปกรณ์ที่จะใช้

pgrepRegex String : รูปแบบชื่อของกระบวนการที่จะฆ่าเพื่อมอบให้กับ pgrep

beforeCloseKill Runnable : เรียกใช้สำหรับการดำเนินการใด ๆ ที่ต้องล้างข้อมูลก่อนที่จะฆ่ากระบวนการในสภาพแวดล้อมปกติเมื่อสิ้นสุดการทดสอบ สามารถเป็นโมฆะได้

การส่งคืน
AutoCloseable วัตถุที่จะหยุดกระบวนการอีกครั้งเมื่อถูกปิด

ขว้าง
DeviceNotAvailableException
TimeoutException
ProcessUtil.KillException