termux 开源项目学习分析

Termux - 适用于 Android 操作系统的终端模拟器应用程序,可通过各种软件包进行扩展。

termux-app

//覆盖下载,Bootstrap zip包  ,地址页:https://github.com/termux/termux-packages/releases/tag/bootstrap-2021.11.07-r1

def downloadBootstrap(String arch, String expectedChecksum, String version) {
...
...

打包成so文件
termux-bootstrap-zip.S

     .global blob
     .global blob_size
     .section .rodata
 blob:
 #if defined __i686__
     .incbin "bootstrap-i686.zip"
 #elif defined __x86_64__
     .incbin "bootstrap-x86_64.zip"
 #elif defined __aarch64__
     .incbin "bootstrap-aarch64.zip"
 #elif defined __arm__
     .incbin "bootstrap-arm.zip"
 #else
 # error Unsupported arch
 #endif
 1:
 blob_size:
     .int 1b - blob

final class TermuxInstaller {
    
    

//读取zip数据
public static native byte[] getZip();
}
//修改文件权限
Os.chmod
//Android 上创建符号链接
Os.symlink

相关实现重要类

//服务
TermuxService
//Termux会话
TermuxSession
//执行命令
ExecutionCommand
//终端会话客户端接口
TerminalSessionClient
//终端会话
TerminalSession
//终端View
TerminalView
//将文本渲染到屏幕中。
TerminalEmulator
//安装bootstrap包的资源,创建相应环境
TermuxInstaller
//Native 实现的伪终端, /dev/ptmx和/dev/pts/
JNI
简化后helloTermux大体过程
TermuxInstaller.setupBootstrapIfNeeded  //启动并安装环境
TermuxService.createTermuxSession  //Termux会话创建,TermuxSession#execute
///随便调试数据,rows = 19,columns = 48
newTerminalSession.initializeEmulator(48,19);
newTerminalSession.write("echo helloTermux");  //写命令

查看知识

Linux伪终端
深入理解Android:Wi-Fi、NFC和GPS卷(完整版)

总结Termux很强大,能来做很多事情

猜你喜欢

转载自blog.csdn.net/CSDNno/article/details/121197292