Skip to content

Root相关

javascript
const core = require('cheese-js');
lua
local core = require('cheese-lua')

请求root权限:requestPermission(timeout: number): boolean

参数:

  • number (timeout): 超时时间/s

返回值:

  • 🟢boolean: true
  • 🔴boolean: false

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块

const root = core.root;
if (root.requestPermission(3)) {
    console.log("root权限请求成功")
}else{
    console.log("root权限请求失败")
}
lua
local core = require('cheese-lua')
local root = core.root
if root.requestPermission(3) then
    print("root权限请求成功")
else
    print("root权限请求失败")
end

检查root权限:checkPermission(): boolean

返回值:

  • 🟢boolean:true
  • 🔴boolean:fasle

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块

const root = core.root;
if (root.checkPermission()) {
    console.log("root权限正常")
}else{
    console.log("root权限不正常")
}
lua
local core = require('cheese-lua')
local root = core.root
if root.checkPermission() then
    print("root权限正常")
else
    print("root权限不正常")
end

root模式开启无障碍:openAccessibilityApi(timeout: number): boolean

说明:

  • 在 root 模式下直接尝试启用无障碍服务,用于提升授权效率

参数:

  • number (timeout): 等待授权生效的超时时间(秒)

返回值:

  • 🟢boolean: true(启用成功)
  • 🔴boolean: false(失败或超时)

用法示例:

javascript
const core = require('cheese-js');
const root = core.root;
if (root.requestPermission(3)) {
    console.log("root权限已获取");
    console.log("无障碍开启结果", root.openAccessibilityApi(10));
}
lua
local core = require('cheese-lua')
local root = core.root
if root.requestPermission(3) then
    print("root权限已获取")
    print("无障碍开启结果", root.openAccessibilityApi(10))
end

root截屏并裁剪:captureScreen(left: number, top: number, right: number, bottom: number): Bitmap

说明:

  • 在 root 模式下直接截屏,支持按坐标裁剪
  • 当参数无效(如 left < 0right <= left)时,返回整屏位图

参数:

  • number (left): 裁剪区域左坐标
  • number (top): 裁剪区域上坐标
  • number (right): 裁剪区域右坐标
  • number (bottom): 裁剪区域下坐标

返回值:

  • 🟢Bitmap: 截屏位图对象
  • 🔴null

用法示例:

javascript
const core = require('cheese-js');
const root = core.root;
const image = core.image;

if (root.requestPermission(3)) {
    const bitmap = root.captureScreen(100, 200, 700, 1200);
    if (bitmap) {
        image.showBitmapView(bitmap);
        image.release(bitmap);
    }
}
lua
local core = require('cheese-lua')
local root = core.root
local image = core.image

if root.requestPermission(3) then
    local bitmap = root.captureScreen(100, 200, 700, 1200)
    if bitmap then
        image.showBitmapView(bitmap)
        image.release(bitmap)
    end
end

执行su命令:exec(command: string): string

参数:

  • string (command): 执行的具体命令

返回值:

  • 🟢string:执行结果
  • 🔴null

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块

const root = core.root;
if (root.requestPermission(3)) {
    console.log("root权限请求成功")
    console.log("执行结果",root.exec("input tap 200 300"))
}else{
    console.log("root权限请求失败")
}
lua
local core = require('cheese-lua')
local root = core.root
if root.requestPermission(3) then
    print("root权限请求成功")
    print("执行结果", root.exec("input tap 200 300"))
else
    print("root权限请求失败")
end

Released under the GPL-3.0 License.