### Install kernelsu-alt Package Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Install the kernelsu-alt package using npm. ```sh npm i kernelsu-alt ``` -------------------------------- ### Get Package Information Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Use `getPackagesInfo` to retrieve detailed information for one or more installed packages. Provide a single package name or an array of names. The returned object includes details like versionName, versionCode, appLabel, isSystem, and uid. ```javascript import { getPackagesInfo } from 'kernelsu-alt'; // Get info for a single package const info = await getPackagesInfo('com.android.settings'); console.log(info); // Get info for multiple packages const infos = await getPackagesInfo(['com.android.settings', 'com.android.shell']); console.log(infos); ``` -------------------------------- ### listPackages Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Lists installed packages on the Android system. ```APIDOC ## listPackages ### Description Lists installed packages on the Android system. ### Parameters - `type` `` - The type of packages to list. Can be one of `'user'`, `'system'`, or `'all'`. Defaults to `'all'`. ### Request Example ```javascript import { listPackages } from 'kernelsu-alt'; // Get all installed packages const allPackages = await listPackages(); console.log(allPackages); // Get only user-installed packages const userPackages = await listPackages('user'); console.log(userPackages); ``` ### Response - `Promise` - Resolves to an array of package names. ``` -------------------------------- ### List Installed Android Packages Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Queries the Android package manager and returns a Promise resolving to an array of package name strings. An optional `type` argument filters the result. ```javascript import { listPackages } from 'kernelsu-alt'; // Get all installed packages const allPackages = await listPackages(); console.log('Total packages:', allPackages.length); // ['com.android.settings', 'com.google.android.gms', ...] // Get only user-installed packages const userPackages = await listPackages('user'); console.log('User packages:', userPackages); // Get only system packages const systemPackages = await listPackages('system'); console.log('System packages:', systemPackages.length); // Check if a specific package is installed const isInstalled = allPackages.includes('com.termux'); console.log('Termux installed:', isInstalled); // Render a list in the UI const listEl = document.getElementById('package-list'); userPackages.forEach((pkg) => { const li = document.createElement('li'); li.textContent = pkg; listEl.appendChild(li); }); ``` -------------------------------- ### Execute a root command and get output Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Use `exec` to run a single command in a root shell and capture its exit code, stdout, and stderr. Suitable for one-off commands. ```javascript import { exec } from 'kernelsu-alt'; // List files in /data/local/tmp as root const { errno, stdout, stderr } = await exec('ls -lh /data/local/tmp', { cwd: '/data/local/tmp', env: { MY_VAR: 'hello' }, }); if (errno === 0) { console.log('Command succeeded'); console.log(stdout); // Example output: // total 12K // -rw-r--r-- 1 root root 1.2K 2024-01-01 12:00 example.txt } else { console.error('Command failed:', stderr); } // Read a protected system file const { errno: e2, stdout: content } = await exec('cat /proc/version'); if (e2 === 0) { console.log('Kernel version:', content.trim()); } ``` -------------------------------- ### List Installed Packages Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Use `listPackages` to retrieve a list of installed packages on the Android system. You can specify the type of packages to list ('user', 'system', or 'all'). Defaults to 'all'. ```javascript import { listPackages } from 'kernelsu-alt'; // Get all installed packages const allPackages = await listPackages(); console.log(allPackages); // Get only user-installed packages const userPackages = await listPackages('user'); console.log(userPackages); ``` -------------------------------- ### Spawn a long-running root process with streaming I/O Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Use `spawn` to start a persistent process in a root shell and stream its stdout and stderr. Ideal for commands that produce continuous or large output. ```javascript import { spawn } from 'kernelsu-alt'; // Stream output of a log-tailing command const logcat = spawn('logcat', ['-v', 'time', '-s', 'MyModule:*']); logcat.stdout.on('data', (data) => { console.log('[stdout]', data); }); logcat.stderr.on('data', (data) => { console.error('[stderr]', data); }); logcat.on('exit', (code) => { console.log(`logcat exited with code ${code}`); }); logcat.on('error', (err) => { console.error('Failed to start process:', err); }); // Another example: run a shell script and stream its output const installer = spawn('sh', ['/data/local/tmp/install.sh']); installer.stdout.on('data', (chunk) => { document.getElementById('progress').textContent += chunk; }); installer.on('exit', (code) => { if (code === 0) { alert('Installation complete!'); } else { alert(`Installation failed with code ${code}`); } }); ``` -------------------------------- ### Execute Command with Root Privileges Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Use the `exec` function to spawn a root shell and run a command. It returns a Promise that resolves with the command's exit code, stdout, and stderr. Ensure the command is a string with space-separated arguments. ```javascript import { exec } from 'kernelsu-alt'; const { errno, stdout, stderr } = await exec('ls -l', { cwd: '/tmp' }); if (errno === 0) { // success console.log(stdout); } ``` -------------------------------- ### spawn Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Spawns a new process using the given command in a root shell, with command-line arguments. ```APIDOC ## spawn ### Description Spawns a new process using the given `command` in **root** shell, with command-line arguments in `args`. If omitted, `args` defaults to an empty array. Returns a `ChildProcess`, Instances of the ChildProcess represent spawned child processes. ### Parameters - `command` `` - The command to run. - `args` `` - List of string arguments. - `options` ``: - `cwd` `` - Current working directory of the child process - `env` `` - Environment key-value pairs ### Request Example ```javascript import { spawn } from 'kernelsu-alt'; const ls = spawn('ls', ['-lh', '/data']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); ls.on('exit', (code) => { console.log(`child process exited with code ${code}`); }); ``` ### ChildProcess Instances of the ChildProcess represent spawned child processes. #### Event 'exit' - `code` `` - The exit code if the child exited on its own. The `'exit'` event is emitted after the child process ends. If the process exited, `code` is the final exit code of the process, otherwise null. #### Event 'error' - `err` `` - The error. The `'error'` event is emitted whenever: - The process could not be spawned. - The process could not be killed. #### `stdout` A `Readable Stream` that represents the child process's `stdout`. ```javascript const subprocess = spawn('ls'); subprocess.stdout.on('data', (data) => { console.log(`Received chunk ${data}`); }); ``` #### `stderr` A `Readable Stream` that represents the child process's `stderr`. ``` -------------------------------- ### exec Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Spawns a root shell and runs a command within that shell, passing the stdout and stderr to a Promise when complete. ```APIDOC ## exec ### Description Spawns a **root** shell and runs a command within that shell, passing the `stdout` and `stderr` to a Promise when complete. ### Parameters - `command` `` - The command to run, with space-separated arguments. - `options` `` - `cwd` `` - Current working directory of the child process - `env` `` - Environment key-value pairs ### Request Example ```javascript import { exec } from 'kernelsu-alt'; const { errno, stdout, stderr } = await exec('ls -l', { cwd: '/tmp' }); if (errno === 0) { // success console.log(stdout); } ``` ### Response - `errno` `` - The exit code of the command. - `stdout` `` - The standard output of the command. - `stderr` `` - The standard error of the command. ``` -------------------------------- ### Spawn Root Shell Process Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Use the `spawn` function to create a new process in a root shell. It returns a `ChildProcess` instance. You can capture `stdout`, `stderr`, and listen for the `'exit'` event. The `args` parameter is an array of string arguments. ```javascript import { spawn } from 'kernelsu-alt'; const ls = spawn('ls', ['-lh', '/data']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); ls.on('exit', (code) => { console.log(`child process exited with code ${code}`); }); ``` -------------------------------- ### exec Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Runs a command in a root shell and awaits its completion, returning the exit code, stdout, and stderr. ```APIDOC ## exec ### Description Runs a command in a root shell and awaits the result. It spawns a root shell, executes the given command string, and resolves a Promise with the process's `errno`, `stdout`, and `stderr` once it exits. This is the simplest way to run a one-shot command and capture its complete output. ### Method `exec(command: string, options?: { cwd?: string, env?: Record }): Promise<{ errno: number, stdout: string, stderr: string }> ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { exec } from 'kernelsu-alt'; const { errno, stdout, stderr } = await exec('ls -lh /data/local/tmp', { cwd: '/data/local/tmp', env: { MY_VAR: 'hello' }, }); if (errno === 0) { console.log('Command succeeded'); console.log(stdout); } else { console.error('Command failed:', stderr); } ``` ### Response #### Success Response (Promise resolves) - **errno** (number) - The exit code of the process. - **stdout** (string) - The standard output of the process. - **stderr** (string) - The standard error of the process. #### Response Example ```json { "errno": 0, "stdout": "total 12K\n-rw-r--r-- 1 root root 1.2K 2024-01-01 12:00 example.txt\n", "stderr": "" } ``` ``` -------------------------------- ### fullScreen Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Requests the WebView to enter or exit full screen mode. ```APIDOC ## fullScreen ### Description Request the WebView enter/exit full screen. ### Parameters - `enter` `` - `true` to enter full screen, `false` to exit. ### Request Example ```javascript import { fullScreen } from 'kernelsu-alt'; fullScreen(true); ``` ``` -------------------------------- ### Retrieve Detailed Package Information Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Accepts a package name or array of names and returns detailed info including version, label, and UID. Useful for checking app status or requirements. ```javascript import { getPackagesInfo } from 'kernelsu-alt'; // Get detailed info for a single package const info = await getPackagesInfo('com.android.settings'); console.log(info); // { // packageName: 'com.android.settings', // versionName: '14', // versionCode: 14000, // appLabel: 'Settings', // isSystem: true, // uid: 1000 // } // Get info for multiple packages at once const infos = await getPackagesInfo([ 'com.android.settings', 'com.termux', 'com.google.android.gms', ]); infos.forEach(({ packageName, appLabel, versionName, isSystem, uid }) => { console.log(`${appLabel} (${packageName}) v${versionName} — system: ${isSystem}, uid: ${uid}`); }); // Settings (com.android.settings) v14 — system: true, uid: 1000 // Termux (com.termux) v0.118.0 — system: false, uid: 10234 // Google Play services (com.google.android.gms) v23.0 — system: true, uid: 10012 // Practical: show a warning if a required companion app is missing or outdated const [companion] = await getPackagesInfo(['com.example.companion']); if (!companion || companion.versionCode < 200) { toast('Please update the companion app to v2.0 or later.'); } ``` -------------------------------- ### Toggle WebView full-screen mode Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Use `fullScreen` to request the hosting WebView to enter or exit full-screen mode, controlling system UI visibility. Pass `true` to enter and `false` to exit. ```javascript import { fullScreen } from 'kernelsu-alt'; // Enter full screen when a media player opens function openPlayer() { fullScreen(true); document.getElementById('player').style.display = 'block'; } // Restore normal layout when the player closes function closePlayer() { fullScreen(false); document.getElementById('player').style.display = 'none'; } // Toggle based on current state let isFullScreen = false; document.getElementById('toggleBtn').addEventListener('click', () => { isFullScreen = !isFullScreen; fullScreen(isFullScreen); }); ``` -------------------------------- ### spawn Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Spawns a long-running process in a root shell, providing streaming I/O capabilities. ```APIDOC ## spawn ### Description Spawns a long-running root process with streaming I/O. It starts a new process in a root shell and returns a `ChildProcess` instance immediately, allowing the caller to stream `stdout` and `stderr` data as it arrives and react to the process exit code. This is suited for long-running commands or commands that produce large or incremental output. ### Method `spawn(command: string, args?: string[], options?: { cwd?: string, env?: Record }): ChildProcess ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { spawn } from 'kernelsu-alt'; const logcat = spawn('logcat', ['-v', 'time', '-s', 'MyModule:*']); logcat.stdout.on('data', (data) => { console.log('[stdout]', data); }); logcat.stderr.on('data', (data) => { console.error('[stderr]', data); }); logcat.on('exit', (code) => { console.log(`logcat exited with code ${code}`); }); logcat.on('error', (err) => { console.error('Failed to start process:', err); }); ``` ### Response #### Success Response (Returns ChildProcess instance) - **ChildProcess** - An object with `stdout`, `stderr` streams and `on('exit')`, `on('error')` event listeners. #### Response Example (See Request Example for usage of ChildProcess instance) ``` -------------------------------- ### listPackages Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Queries the Android package manager and returns a Promise resolving to an array of package name strings. An optional `type` argument can filter the results. ```APIDOC ## listPackages ### Description Queries the Android package manager and returns a Promise resolving to an array of package name strings. An optional `type` argument filters the result to `'user'` (user-installed apps), `'system'` (system apps), or `'all'` (default). ### Method JavaScript Function Call ### Parameters - **type** (string) - Optional - Filters the results. Accepts `'user'`, `'system'`, or `'all'`. Defaults to `'all'`. ### Request Example ```javascript import { listPackages } from 'kernelsu-alt'; const userPackages = await listPackages('user'); console.log('User packages:', userPackages); ``` ### Response #### Success Response - **packages** (array of strings) - An array containing the package names. ### Response Example ```json ["com.android.settings", "com.google.android.gms", "com.termux"] ``` ``` -------------------------------- ### enableEdgeToEdge Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Requests the WebView to set padding to 0 or system bar insets. ```APIDOC ## enableEdgeToEdge ### Description Request the WebView to set padding to 0 or system bar insets. - tips: this is disabled by default but if you request resource from `internal/insets.css`, this will be enabled automatically. - To get insets value and enable this automatically, you can - add `@import "https://mui.kernelsu.org/internal/insets.css";` in css OR - add `` in html. - Note: `enableInsets` is renamed to `enableEdgeToEdge` since KernelSU 32265. Old api is kept and marked as deprecated for compatibility, there is no plan to remove it currently. ### Parameters - `enable` `` - `true` to enable edge-to-edge mode, `false` to disable. ### Request Example ```javascript import { enableEdgeToEdge } from 'kernelsu-alt'; const result = await enableEdgeToEdge(true); if (!result) { console.log('Function not implemented'); } ``` ### Response - `result` `` - Indicates if the function was successfully called (implementation status). ``` -------------------------------- ### getPackagesInfo Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Retrieves detailed information for one or more packages. ```APIDOC ## getPackagesInfo ### Description Retrieves detailed information for one or more packages. ### Parameters - `pkg` `` - A single package name or an array of package names. ### Request Example ```javascript import { getPackagesInfo } from 'kernelsu-alt'; // Get info for a single package const info = await getPackagesInfo('com.android.settings'); console.log(info); // Get info for multiple packages const infos = await getPackagesInfo(['com.android.settings', 'com.android.shell']); console.log(infos); ``` ### Response - `Promise` - Resolves to: - A single package information object if a single package name is provided. - An array of package information objects if an array of package names is provided. The `PackagesInfo` object has the following structure: - `packageName` `` - Package name of the application. - `versionName` `` - Version of the application. - `versionCode` `` - Version code of the application. - `appLabel` `` - Display name of the application. - `isSystem` `` - Whether the application is a system app. - `uid` `` - UID of the application. ``` -------------------------------- ### Control WebView Fullscreen Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Use the `fullScreen` function to request the WebView to enter or exit fullscreen mode. Pass `true` to enter and `false` to exit. ```javascript import { fullScreen } from 'kernelsu-alt'; fullScreen(true); ``` -------------------------------- ### toast Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Displays a toast message on the screen. ```APIDOC ## toast ### Description Show a toast message. ### Parameters - `message` `` - The message to display in the toast. ### Request Example ```javascript import { toast } from 'kernelsu-alt'; toa st('Hello, world!'); ``` ``` -------------------------------- ### Show Toast Message Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Display a brief message to the user using the `toast` function. The message is passed as a string argument. ```javascript import { toast } from 'kernelsu-alt'; toa('Hello, world!'); ``` -------------------------------- ### Enable/Disable Edge-to-Edge Rendering Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Requests the WebView to extend content beneath system bars. Returns a Promise indicating support. Can also be enabled via CSS/HTML imports. ```javascript import { enableEdgeToEdge } from 'kernelsu-alt'; // Enable edge-to-edge layout on app start async function initLayout() { const supported = await enableEdgeToEdge(true); if (!supported) { console.warn('Edge-to-edge not supported on this KernelSU version, falling back.'); document.body.classList.add('no-edge-to-edge'); } else { document.body.classList.add('edge-to-edge'); } } initLayout(); // Alternatively, enable automatically via CSS import in your stylesheet: // @import "https://mui.kernelsu.org/internal/insets.css"; // // Or in HTML: // // Disable edge-to-edge when switching to a form screen async function showFormScreen() { await enableEdgeToEdge(false); document.getElementById('form-screen').style.display = 'block'; } ``` -------------------------------- ### enableEdgeToEdge Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Requests the WebView to enable or disable edge-to-edge rendering. When enabled, WebUI content extends beneath the status and navigation bars. Returns a Promise resolving to a boolean indicating feature support. ```APIDOC ## enableEdgeToEdge ### Description Enable or disable edge-to-edge rendering in the WebView. When enabled, the WebUI content extends beneath the status and navigation bars. The function returns a Promise resolving to a boolean indicating whether the feature is supported by the current KernelSU version. ### Method JavaScript Function Call ### Parameters - **enable** (boolean) - Required - `true` to enable edge-to-edge, `false` to disable. ### Request Example ```javascript import { enableEdgeToEdge } from 'kernelsu-alt'; async function initLayout() { const supported = await enableEdgeToEdge(true); if (!supported) { console.warn('Edge-to-edge not supported on this KernelSU version, falling back.'); } } initLayout(); ``` ### Response #### Success Response - **supported** (boolean) - `true` if edge-to-edge rendering is supported, `false` otherwise. ### Response Example ```json true ``` ``` -------------------------------- ### Enable Edge-to-Edge WebView Display Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Use `enableEdgeToEdge` to request the WebView to set padding to 0 or system bar insets. This is disabled by default but can be enabled automatically by importing `internal/insets.css`. ```javascript import { enableEdgeToEdge } from 'kernelsu-alt'; const result = await enableEdgeToEdge(true); if (!result) { console.log('Function not implemented'); } ``` -------------------------------- ### Handle ChildProcess stdout Stream Source: https://github.com/kowx712/kernelsu-alt/blob/master/README.md Listen for data chunks on the `stdout` stream of a spawned subprocess. This is useful for real-time output processing. ```javascript const subprocess = spawn('ls'); subprocess.stdout.on('data', (data) => { console.log(`Received chunk ${data}`); }); ``` -------------------------------- ### toast Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Displays a short-lived, non-blocking native Android toast notification with the provided message string. Useful for user feedback without interrupting the UI flow. ```APIDOC ## toast ### Description Shows a short-lived, non-blocking native Android toast notification with the given message string. It is useful for providing feedback to the user without interrupting the UI flow. ### Method JavaScript Function Call ### Parameters - **message** (string) - Required - The message to display in the toast. ### Request Example ```javascript import { toast } from 'kernelsu-alt'; tOast('Module settings saved successfully!'); ``` ### Response This function does not return a value. ``` -------------------------------- ### Display Native Android Toast Message Source: https://context7.com/kowx712/kernelsu-alt/llms.txt Shows a short-lived, non-blocking native Android toast notification. Useful for user feedback without interrupting the UI flow. ```javascript import { toast } from 'kernelsu-alt'; // Simple success notification toa st('Module settings saved successfully!'); // Use after an async operation completes async function applySettings() { const { errno, stderr } = await exec('sh /data/adb/modules/mymodule/apply.sh'); if (errno === 0) { toast('Settings applied. Reboot may be required.'); } else { toast(`Error applying settings: ${stderr.slice(0, 80)}`); } } applySettings(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.