Skip to content
On this page

Root相关

typescript
import core from 'cheese-core';
const root = core.root;

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

参数:

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

返回值:

  • 🟢boolean: true
  • 🔴boolean: false

用法示例:

typescript
if (root.requestPermission(3)) {
    console.log("请求成功")
}

检查root权限:checkPermission(): boolean

返回值:

  • 🟢boolean:true
  • 🔴boolean:fasle

用法示例:

typescript
if (root.checkPermission()) {
    console.log("root权限正常")
}

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

参数:

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

返回值:

  • 🟢string:执行结果
  • 🔴null

用法示例:

typescript
if (root.checkPermission()) {
    root.exec("input tap 200 300")
}

解析事件:parseEvent(str: String): string

参数:

  • string (command): 解析的具体事件

返回值:

  • 🟢string:解析结果
  • 🔴null

用法示例:

typescript
if (root.checkPermission()) {
    let cmd=root.parseEvent(`
/dev/input/event2: 0003 0039 00000071
/dev/input/event2: 0001 014a 00000001
/dev/input/event2: 0003 0035 000002e4
/dev/input/event2: 0003 0036 00000160
/dev/input/event2: 0000 0000 00000000
/dev/input/event2: 0003 0039 ffffffff
/dev/input/event2: 0001 014a 00000000
/dev/input/event2: 0000 0000 00000000
`)
    root.exec(cmd)


}