### Go System Process Management: PID, Memory, CPU, Restart, Boot Start Source: https://context7.com/dasongzi1366/autogo/llms.txt Monitor processes and control application lifecycle using Go. Allows retrieving process IDs by name, getting memory and CPU usage for specific processes or the current process, restarting the application, and configuring boot auto-start (requires root privileges). Utilizes the 'github.com/Dasongzi1366/AutoGo/system' package. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/system" ) func main() { // Get process ID by name pid := system.GetPid("com.android.chrome") if pid > 0 { fmt.Printf("Chrome PID: %d\n", pid) // Memory usage in KB memUsage := system.GetMemoryUsage(pid) fmt.Printf("Memory: %d KB\n", memUsage) // CPU usage percentage cpuUsage := system.GetCpuUsage(pid) fmt.Printf("CPU: %.2f%%\n", cpuUsage) } // Get current process stats currentMem := system.GetMemoryUsage(0) currentCpu := system.GetCpuUsage(0) fmt.Printf("Self - Memory: %d KB, CPU: %.2f%%\n", currentMem, currentCpu) // Restart self (exits with code 123) // system.RestartSelf() // Set boot auto-start (requires root) system.SetBootStart(true) system.SetBootStart(false) // Disable } ``` -------------------------------- ### App Management with AutoGo in Go Source: https://context7.com/dasongzi1366/autogo/llms.txt Manages Android applications, including launching, installing, uninstalling, and controlling their state. It can also open URLs and view files. Dependencies include the 'github.com/Dasongzi1366/AutoGo/app' package. It takes package names, file paths, and intent options as input and returns boolean values or prints information. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/app" ) func main() { // Launch an application by package name if app.Launch("com.android.chrome") { fmt.Println("Chrome launched successfully") } // Get current app package and activity pkg := app.CurrentPackage() activity := app.CurrentActivity() fmt.Printf("Current: %s/%s\n", pkg, activity) // Check if app is installed if app.IsInstalled("com.example.app") { // Force stop the app app.ForceStop("com.example.app") // Clear app data app.Clear("com.example.app") // Uninstall the app app.Uninstall("com.example.app") } // Install APK app.Install("/sdcard/Download/app.apk") // Open URL in browser app.OpenUrl("https://example.com") // Open file with default app app.ViewFile("/sdcard/document.pdf") // Start activity with intent options app.StartActivity(app.IntentOptions{ Action: "VIEW", Data: "https://example.com", PackageName: "com.android.chrome", Extras: map[string]string{ "key": "value", }, }) // Send broadcast app.SendBroadcast(app.IntentOptions{ Action: "android.intent.action.BOOT_COMPLETED", }) } ``` -------------------------------- ### Go HTTP Client: GET and POST Multipart Requests Source: https://context7.com/dasongzi1366/autogo/llms.txt Simple HTTP client for making GET and POST requests in Go. Supports setting a timeout for GET requests and performing multipart file uploads for POST requests. Requires the 'github.com/Dasongzi1366/AutoGo/https' package. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/https" ) func main() { // GET request with timeout (milliseconds, 0 = no timeout) code, data := https.Get("https://api.example.com/data", 5000) if code == 200 { fmt.Printf("Response: %s\n", string(data)) } else { fmt.Printf("HTTP error: %d\n", code) } // POST multipart file upload fileData := []byte("file contents") code, response := https.PostMultipart( "https://api.example.com/upload", "document.txt", fileData, ) if code == 200 { fmt.Printf("Upload response: %s\n", string(response)) } } ``` -------------------------------- ### Perform Image Processing and Recognition Source: https://context7.com/dasongzi1366/autogo/llms.txt This Go snippet outlines functionalities for image processing and recognition. It includes methods to capture screenshots, get pixel colors at specific coordinates, and compare colors with a given similarity threshold. Advanced features like finding colors within a region, locating multiple colors with offsets, and counting color occurrences are also provided. The code demonstrates how to detect multiple colors at specific coordinates, capture screen regions, and save screenshots. It also covers reading images from various sources (path, URL, base64) and performing common image manipulations such as clipping, resizing, rotating, converting to grayscale, and applying binarization and adaptive thresholding. Finally, it shows how to encode images into different formats (PNG, JPG) and base64. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/images" ) func main() { // Get pixel color at coordinates color := images.Pixel(100, 200) fmt.Printf("Color at (100,200): #%s\n", color) // Compare color with similarity threshold (0.0-1.0) if images.CmpColor(100, 200, "FF0000", 0.9) { fmt.Println("Red color detected") } // Find color in region, direction: 0=L->R,T->B, 1=R->L,T->B, 2=L->R,B->T, 3=R->L,B->T x, y := images.FindColor(0, 0, 1080, 1920, "FF0000", 0.9, 0) if x != -1 { fmt.Printf("Red found at (%d,%d)\n", x, y) } // Find multiple colors with offsets // Format: "baseColor,offsetX1,offsetY1,color1,offsetX2,offsetY2,color2,..." x, y = images.FindMultiColors(0, 0, 1080, 1920, "FF0000,10,0,00FF00,20,0,0000FF", 0.9, 0) if x != -1 { fmt.Printf("Color pattern found at (%d,%d)\n", x, y) } // Count color occurrences in region count := images.GetColorCountInRegion(0, 0, 1080, 1920, "FF0000", 0.9) fmt.Printf("Red pixels: %d\n", count) // Detect multiple colors at specific coordinates // Format: "x1,y1,color1,x2,y2,color2,..." if images.DetectsMultiColors("100,200,FF0000,150,250,00FF00", 0.9) { fmt.Println("All colors match") } // Capture screen region img := images.CaptureScreen(0, 0, 1080, 1920) // Save screenshot images.Save(img, "/sdcard/screenshot.png", 100) // Read image from file/URL/base64 img1 := images.ReadFromPath("/sdcard/template.png") img2 := images.ReadFromUrl("https://example.com/image.png") img3 := images.ReadFromBase64("iVBORw0KGgo...") // Image manipulation clipped := images.Clip(img, 100, 100, 500, 500) resized := images.Resize(img, 540, 960) rotated := images.Rotate(img, 90) gray := images.Grayscale(img) binary := images.ApplyBinarization(img, 128) // Advanced thresholding threshold := images.ApplyThreshold(img, 128, 255, "BINARY") adaptive := images.ApplyAdaptiveThreshold(img, 255, "GAUSSIAN_C", "BINARY", 11, 2.0) // Encode to formats pngData := images.EncodeToBytes(img, "png", 100) jpgData := images.EncodeToBytes(img, "jpg", 85) base64Str := images.EncodeToBase64(img, "png", 100) fmt.Printf("Encoded to base64: %s...\n", base64Str[:50]) } ``` -------------------------------- ### HTTP Requests API Source: https://context7.com/dasongzi1366/autogo/llms.txt Simple HTTP client for GET and POST operations. ```APIDOC ## HTTP Requests API ### Description Provides functions for making HTTP GET and POST requests, including support for multipart file uploads and request timeouts. ### Functions - **Get(url string, timeout int) (int, []byte)**: Performs an HTTP GET request to the specified URL with a given timeout in milliseconds (0 for no timeout). Returns the HTTP status code and response body. - **PostMultipart(url string, filename string, data []byte) (int, []byte)**: Performs an HTTP POST request to upload a file as multipart data. Sends the file with the given filename and data. Returns the HTTP status code and response body. ``` -------------------------------- ### Handle Text Input and Clipboard with Go IME Package Source: https://context7.com/dasongzi1366/autogo/llms.txt This Go code snippet demonstrates handling text input and clipboard operations using the 'ime' package. It covers inputting text (including multi-byte characters via clipboard), setting and retrieving clipboard content, listing available input methods, and switching input methods. It also shows how to send key events. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/ime" ) func main() { // Input text (handles Chinese characters via clipboard) ime.InputText("Hello World") ime.InputText("你好世界") // Clipboard operations ime.SetClipText("Text to copy") clipContent := ime.GetClipText() fmt.Printf("Clipboard: %s\n", clipContent) // List available IMEs imeList := ime.GetIMEList() for _, imeId := range imeList { fmt.Printf("IME: %s\n", imeId) } // Switch input method if len(imeList) > 0 { ime.SetCurrentIME(imeList[0]) } // Send key events ime.KeyAction(66) // KEYCODE_ENTER ime.KeyAction(67) // KEYCODE_DEL } ``` -------------------------------- ### Display Console and UI Overlays with Go Source: https://context7.com/dasongzi1366/autogo/llms.txt This Go snippet demonstrates how to initialize and manage a floating console and UI elements like toasts, HUDs, and drawing primitives using the AutoGo library. It covers console configuration, displaying messages, toast notifications, HUD customization, drawing shapes and images, and alert dialogs. Dependencies include the 'console' and 'imgui' packages from the AutoGo library. ```go package main import ( "github.com/Dasongzi1366/AutoGo/console" "github.com/Dasongzi1366/AutoGo/imgui" "time" ) func main() { // Console initialization (auto-called on first use) console.Init(false) // false = normal mode, true = no-capture mode // Configure console appearance console.SetWindowSize(600, 400) console.SetWindowPosition(50, 100) console.SetWindowColor("#000000") console.SetTextColor("#00FF00") console.SetTextSize(16) // Display console console.Show() // Print messages console.Println("Automation started") console.Println("Processing images...") console.Println("Task completed") // Clear console console.Clear() // Hide console console.Hide() // Toast notifications imgui.Init(false) imgui.Toast("Hello from AutoGo!") imgui.ToastSetTextSize(48) // HUD overlay with custom text items imgui.HudInit(10, 10, 500, 200, "#80000000", 32) imgui.HudSetText([]imgui.TextItem{ {TextColor: "#FFFFFF", Text: "FPS: 60"}, {TextColor: "#00FF00", Text: "Status: Running"}, {TextColor: "#FFFF00", Text: "Time: " + time.Now().Format("15:04:05")}, }) // Draw shapes imgui.DrawRect(100, 100, 200, 200, "#FF0000") imgui.DrawLine(0, 0, 500, 500, "#00FF00") // Draw image overlay pngData := []byte{/* PNG bytes */} imgui.DrawImg(50, 50, 250, 250, pngData) // Clear overlays imgui.ClearRect() imgui.ClearLine() imgui.ClearImg() imgui.HudClose() // Alert dialog imgui.Alert("Alert Title", "This is an important message") // Close imgui system imgui.Close() } ``` -------------------------------- ### Go File Operations: Create, Read, Write, Copy, Move, List, Delete Source: https://context7.com/dasongzi1366/autogo/llms.txt Comprehensive file and directory management in Go. Supports checking existence, type checking, reading/writing text and binary data, copying, moving, renaming, path manipulation, listing directory contents, and deletion. Relies on the 'github.com/Dasongzi1366/AutoGo/files' package. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/files" ) func main() { path := "/sdcard/myapp/config.txt" // Check existence if !files.Exists(path) { // Create file with parent directories files.CreateWithDirs(path) } // Type checking if files.IsFile(path) { fmt.Println("It's a file") } if files.IsDir("/sdcard/myapp") { fmt.Println("It's a directory") } if files.IsEmptyDir("/sdcard/myapp") { fmt.Println("Directory is empty") } // Write and read text files.Write(path, "Hello World\n") files.Append(path, "New line\n") content := files.Read(path) fmt.Printf("Content: %s\n", content) // Binary operations data := []byte{0x89, 0x50, 0x4E, 0x47} files.WriteBytes("/sdcard/test.bin", data) readData := files.ReadBytes("/sdcard/test.bin") fmt.Printf("Read %d bytes\n", len(readData)) // File operations files.Copy("/sdcard/source.txt", "/sdcard/backup.txt") files.Move("/sdcard/old.txt", "/sdcard/new.txt") files.Rename("/sdcard/file.txt", "/sdcard/renamed.txt") // Path utilities name := files.GetName(path) // "config.txt" nameOnly := files.GetNameWithoutExtension(path) // "config" ext := files.GetExtension(path) // "txt" // Relative to absolute path absPath := files.Path("./data/file.txt") // List directory contents entries := files.ListDir("/sdcard/Download") for _, entry := range entries { fmt.Printf("Entry: %s\n", entry) } // Delete file or directory files.Remove("/sdcard/temp") } ``` -------------------------------- ### Access Device Information and Control Hardware Source: https://context7.com/dasongzi1366/autogo/llms.txt This Go snippet demonstrates how to access various device properties such as screen dimensions, brand, model, Android version, CPU ABI, and serial number. It also shows how to retrieve device identifiers like IMEI, Android ID, Wi-Fi MAC, and IP address. Furthermore, it includes functionalities for checking and manipulating battery status, memory information, volume controls for music, notifications, and alarms, and screen control including waking up, checking lock status, and keeping the screen on. Vibration control is also demonstrated, noting that it requires root privileges. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/device" ) func main() { // Device screen dimensions (updated automatically) fmt.Printf("Resolution: %dx%d\n", device.Width, device.Height) // Device properties fmt.Printf("Brand: %s\n", device.Brand) fmt.Printf("Model: %s\n", device.Model) fmt.Printf("Android Version: %s (SDK %d)\n", device.Release, device.SdkInt) fmt.Printf("CPU ABI: %s\n", device.CpuAbi) fmt.Printf("Serial: %s\n", device.Serial) // Device identifiers imei := device.GetImei() androidId := device.GetAndroidId() wifiMac := device.GetWifiMac() ip := device.GetIp() fmt.Printf("IMEI: %s, AndroidID: %s\n", imei, androidId) fmt.Printf("WiFi MAC: %s, IP: %s\n", wifiMac, ip) // Battery information battery := device.GetBattery() status := device.GetBatteryStatus() fmt.Printf("Battery: %d%%, Status: %d\n", battery, status) // Simulate battery for testing device.SetBatteryLevel(80) device.SetBatteryStatus(2) // Charging // Memory information (KB) totalMem := device.GetTotalMem() availMem := device.GetAvailMem() fmt.Printf("Memory: %d KB total, %d KB available\n", totalMem, availMem) // Volume control musicVol := device.GetMusicVolume() maxVol := device.GetMusicMaxVolume() device.SetMusicVolume(maxVol / 2) device.SetNotificationVolume(5) device.SetAlarmVolume(10) // Screen control if !device.IsScreenOn() { device.WakeUp() } if !device.IsScreenUnlock() { fmt.Println("Screen is locked") } // Keep screen always on device.KeepScreenOn() // Set screen mode: 0=OFF, 1=DOZE, 2=ON, 3=DOZE_SUSPEND device.SetScreenMode(2) // Vibration (requires root) device.Vibrate(500) // 500ms device.CancelVibration() } ``` -------------------------------- ### Touch and Motion Control with AutoGo in Go Source: https://context7.com/dasongzi1366/autogo/llms.txt Simulates touch gestures, swipes, and hardware key events on Android devices. It supports single taps, long presses, multi-touch, swipes, and various hardware key actions like Home, Back, and Volume. Dependencies include the 'github.com/Dasongzi1366/AutoGo/motion' package. Inputs include coordinates, durations, and keycodes. ```go package main import ( "github.com/Dasongzi1366/AutoGo/motion" ) func main() { // Single tap at coordinates motion.Click(500, 1000, 1) // Long press for 2 seconds motion.LongClick(500, 1000, 2000) // Multi-touch down/move/up motion.TouchDown(100, 200, 1) // Finger 1 motion.TouchDown(300, 400, 2) // Finger 2 motion.TouchMove(150, 250, 1) motion.TouchMove(350, 450, 2) motion.TouchUp(150, 250, 1) motion.TouchUp(350, 450, 2) // Swipe from point A to B over 500ms motion.Swipe(540, 1500, 540, 500, 500) // Alternative swipe algorithm motion.Swipe2(100, 1000, 900, 1000, 300) // Hardware key actions motion.Home() // Press home button motion.Back() // Press back button motion.Recents() // Open recent apps motion.PowerDialog() // Long press power button motion.Notifications() // Open notification shade motion.QuickSettings() // Open quick settings motion.VolumeUp() // Volume up motion.VolumeDown() // Volume down motion.Camera() // Launch camera // Press any keycode motion.KeyAction(motion.KEYCODE_ENTER) motion.KeyAction(motion.KEYCODE_DEL) } ``` -------------------------------- ### Execute Utility Functions with Go Source: https://context7.com/dasongzi1366/autogo/llms.txt This Go snippet illustrates the use of various utility functions provided by the AutoGo library for common operations on Android. It includes logging to logcat, executing shell commands, retrieving screen dimensions, generating cryptographically secure random numbers, pausing execution, and performing type conversions between strings, integers, floats, and booleans. Dependencies include the 'fmt' and 'utils' packages from the AutoGo library. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/utils" ) func main() { // Logging to Android logcat utils.LogI("MyApp", "Information message") utils.LogE("MyApp", "Error message") // Execute shell commands output := utils.Shell("pm list packages") fmt.Printf("Installed packages:\n%s\n", output) // Get screen dimensions width, height := utils.WmSize() fmt.Printf("Screen: %dx%d\n", width, height) // Random numbers (cryptographically secure) randomNum := utils.Random(1, 100) fmt.Printf("Random: %d\n", randomNum) // Sleep utils.Sleep(1000) // 1 second // Type conversions str := utils.I2s(42) // int to string num := utils.S2i("42") // string to int fStr := utils.F2s(3.14159) // float to string fNum := utils.S2f("3.14159") // string to float bStr := utils.B2s(true) // bool to string bVal := utils.S2b("true") // string to bool fmt.Printf("%s, %d, %s, %.2f, %s, %v\n", str, num, fStr, fNum, bStr, bVal) } ``` -------------------------------- ### Automate UI Element Interaction with Go Accessibility Services Source: https://context7.com/dasongzi1366/autogo/llms.txt This Go code snippet demonstrates how to find and interact with UI elements using accessibility services provided by the uiacc package. It covers actions like clicking, setting text, scrolling, and retrieving element properties. Ensure the 'github.com/Dasongzi1366/AutoGo/uiacc' package is correctly imported and accessible. ```go package main import ( "fmt" "github.com/Dasongzi1366/AutoGo/uiacc" ) func main() { // Create new selector node := uiacc.New() // Find button with text "Login" and click if node.Text("Login").Click("Login") { fmt.Println("Login button clicked") } // Chain selectors for precise targeting loginBtn := node. PackageName("com.example.app"). ClassName("android.widget.Button"). TextContains("Login"). Clickable(true). FindOnce() if loginBtn != nil { bounds := loginBtn.GetBounds() fmt.Printf("Button at (%d,%d) size %dx%d\n", bounds.Left, bounds.Top, bounds.Width, bounds.Height) // Click using accessibility action loginBtn.Click() // Or click at center coordinates loginBtn.ClickCenter() // Long press loginBtn.ClickLongClick() } // Wait for element to appear (timeout in ms, 0 = infinite) inputField := node.ClassName("android.widget.EditText").Editable(true).WaitFor(5000) if inputField != nil { // Set text in input field inputField.SetText("username@example.com") // Select text range inputField.SetSelection(0, 8) // Copy/cut/paste inputField.Copy() inputField.Cut() inputField.Paste() } // Find all matching elements buttons := node.ClassName("android.widget.Button").Find() fmt.Printf("Found %d buttons\n", len(buttons)) for i, btn := range buttons { text := btn.GetText() desc := btn.GetDesc() fmt.Printf("Button %d: text='%s' desc='%s'\n", i, text, desc) } // Traverse hierarchy element := node.Id("submit_button").FindOnce() if element != nil { parent := element.GetParent() children := element.GetChildren() child := element.GetChild(0) fmt.Printf("Children count: %d\n", element.GetChildCount()) fmt.Printf("Index in parent: %d\n", element.GetIndex()) } // Scrollable containers scrollView := node.Scrollable(true).FindOnce() if scrollView != nil { scrollView.ScrollForward() scrollView.ScrollBackward() } // Get element properties if element != nil { fmt.Printf("Clickable: %v\n", element.GetClickable()) fmt.Printf("Enabled: %v\n", element.GetEnabled()) fmt.Printf("Visible: %v\n", element.GetVisibleToUser()) fmt.Printf("ClassName: %s\n", element.GetClassName()) fmt.Printf("PackageName: %s\n", element.GetPackageName()) fmt.Printf("ResourceID: %s\n", element.GetId()) } // Close accessibility service when done uiacc.Close() } ``` -------------------------------- ### System Process Management API Source: https://context7.com/dasongzi1366/autogo/llms.txt Monitor processes and control application lifecycle. ```APIDOC ## System Process Management API ### Description Utilities for monitoring system processes, retrieving resource usage, and managing application lifecycle, including restart and boot auto-start configuration. ### Functions - **GetPid(processName string) int**: Retrieves the Process ID (PID) of a process by its name. Returns 0 if not found. - **GetMemoryUsage(pid int) int**: Gets the memory usage (in KB) of a process. Use pid 0 for the current process. - **GetCpuUsage(pid int) float64**: Gets the CPU usage percentage of a process. Use pid 0 for the current process. - **RestartSelf()**: Restarts the current application. The application exits with code 123. - **SetBootStart(enable bool)**: Configures whether the application should start automatically on boot. Requires root privileges. ``` -------------------------------- ### File Operations API Source: https://context7.com/dasongzi1366/autogo/llms.txt Comprehensive file and directory management functions. ```APIDOC ## File Operations API ### Description Provides a set of utilities for managing files and directories, including checking existence, type, creating, reading, writing, copying, moving, renaming, listing, and deleting. ### Functions - **Exists(path string) bool**: Checks if a file or directory exists. - **IsFile(path string) bool**: Checks if the given path is a file. - **IsDir(path string) bool**: Checks if the given path is a directory. - **IsEmptyDir(path string) bool**: Checks if a directory is empty. - **CreateWithDirs(path string)**: Creates a file and its parent directories if they don't exist. - **Write(path string, content string)**: Writes string content to a file, overwriting existing content. - **Append(path string, content string)**: Appends string content to a file. - **Read(path string) string**: Reads the entire content of a file as a string. - **WriteBytes(path string, data []byte)**: Writes byte slice content to a file, overwriting existing content. - **ReadBytes(path string) []byte**: Reads the entire content of a file as a byte slice. - **Copy(src string, dst string)**: Copies a file from source to destination. - **Move(src string, dst string)**: Moves a file or directory from source to destination. - **Rename(oldPath string, newPath string)**: Renames a file or directory. - **GetName(path string) string**: Gets the base name of a path (e.g., "config.txt"). - **GetNameWithoutExtension(path string) string**: Gets the name of a path without its extension (e.g., "config"). - **GetExtension(path string) string**: Gets the extension of a path (e.g., "txt"). - **Path(relativePath string) string**: Converts a relative path to an absolute path. - **ListDir(dirPath string) []string**: Lists the contents of a directory. - **Remove(path string)**: Deletes a file or directory recursively. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.