Compare commits

...

71 Commits

Author SHA1 Message Date
83c1b888b6 <appbase>APK 15.15.14 release Publish. 2026-03-25 20:36:14 +08:00
6afc81939d <appbase>APK 15.15.13 release Publish. 2026-03-25 20:17:45 +08:00
1cf4c67b4f <appbase>APK 15.15.12 release Publish. 2026-03-25 20:17:45 +08:00
89697f8c49 Merge remote-tracking branch 'origin/winboll' into appbase 2026-03-25 20:16:31 +08:00
5419fad1cf 移除通用FTP服务应用数据备份功能 2026-03-25 19:47:06 +08:00
610d3811db 栏目字体与分段调整 2026-03-18 15:49:42 +08:00
2d949eb5a3 分类栏目排版 2026-03-18 15:44:01 +08:00
e6940805d9 明确操作优先级 2026-03-18 15:41:48 +08:00
1641424276 通顺表达句法。 2026-03-18 15:36:58 +08:00
5d1cdff283 使用Markdown语法调整说明书显示格式。 2026-03-18 15:32:49 +08:00
da66cea1e5 详细解析说明 2026-03-18 12:05:42 +08:00
5eb7441dc7 更新说明书 2026-03-18 12:03:32 +08:00
5f3168e17f 更新说明书 2026-03-18 11:49:58 +08:00
e3c4bab6c9 更正项目说明书。 2026-03-18 11:41:23 +08:00
2af6427ca8 精简nfc action 数量 2026-03-17 04:03:20 +08:00
b8c70bef98 调整NFC接口窗体根据动作类型指定对应的脚本运行。 2026-03-16 16:42:02 +08:00
7713d6c460 基本实现NFC Build View 模块功能。 2026-03-15 20:25:16 +08:00
73c69bd665 20260315_193958_991 2026-03-15 19:40:11 +08:00
a076fe50cd 调整Termux 调用模块 UI显示与环境参数配置。 2026-03-15 13:45:49 +08:00
1512b76c36 编译参数修复 2026-03-15 11:55:10 +08:00
850b9af6ec 编译参数修复 2026-03-15 11:52:51 +08:00
31c1592086 Termux终端调用接口完成 2026-03-15 11:50:01 +08:00
b3976a8633 <winboll>APK 15.11.25 release Publish. 2026-03-15 11:48:40 +08:00
ea896228d7 <winboll>APK 15.11.24 release Publish. 2026-03-15 11:46:14 +08:00
d49ecb3943 <winboll>APK 15.11.23 release Publish. 2026-03-15 11:09:40 +08:00
ad3aecf867 <winboll>APK 15.11.22 release Publish. 2026-03-15 11:07:05 +08:00
c417d9732a <winboll>APK 15.11.21 release Publish. 2026-03-15 10:52:23 +08:00
7bd1357c8c <winboll>APK 15.11.20 release Publish. 2026-03-15 10:46:25 +08:00
16a2c3c0c8 <winboll>APK 15.11.19 release Publish. 2026-03-15 10:36:01 +08:00
b747d83972 <winboll>APK 15.11.18 release Publish. 2026-03-15 10:26:55 +08:00
f2788dda96 <winboll>APK 15.11.17 release Publish. 2026-03-15 10:09:28 +08:00
ea3a66bebe <winboll>APK 15.11.16 release Publish. 2026-03-15 10:07:00 +08:00
a53a0cbcdc <winboll>APK 15.11.15 release Publish. 2026-03-13 13:41:48 +08:00
17d1c2f321 Merge remote-tracking branch 'origin/winboll' into appbase 2026-02-04 13:14:53 +08:00
94ac2d9f9c 更新编译说明 2026-02-04 13:13:58 +08:00
447b7fa5a8 Merge remote-tracking branch 'origin/winboll' into appbase 2026-02-04 12:39:22 +08:00
11d7846cd2 更新项目说明书 2026-02-04 12:38:17 +08:00
dae39b43d6 添加FTP备份目标保存路径设置。 2026-01-31 21:03:39 +08:00
530316b976 添加data与sdcard两种应用数据测试。 2026-01-31 20:07:56 +08:00
3f924b004c 完成应用Data区数据备份测试。 2026-01-31 19:47:12 +08:00
1db94b52e6 完成二次备份点击功能 2026-01-31 18:52:01 +08:00
55c653af09 应用备份打包上传功能完成 2026-01-31 14:18:26 +08:00
9d97d6ed94 正在调试FTP应用备份功能。 2026-01-30 21:38:04 +08:00
21e464bf5e <winboll>APK 15.11.14 release Publish. 2026-01-29 17:03:53 +08:00
47f27b6bcb 修复调试工具配置误差 2026-01-29 17:00:59 +08:00
013ad7ff1b <winboll>APK 15.11.13 release Publish. 2026-01-24 21:19:19 +08:00
ab6fd0c6b5 增加对签名证书修改后的证书识别能力。 2026-01-24 21:17:54 +08:00
e21bb9058d <libappbase>Library Release 15.15.11 2026-01-24 20:32:30 +08:00
ad6175f977 <appbase>APK 15.15.11 release Publish. 2026-01-24 20:32:20 +08:00
8b659f4b24 编译参数修复 2026-01-24 20:31:49 +08:00
13b841f923 <libappbase>Library Release 15.15.10 2026-01-24 20:29:06 +08:00
0aaf71f285 添加对签名证书修改后的证书识别能力。 2026-01-24 19:50:43 +08:00
3c1afc1c0b <winboll>APK 15.11.12 release Publish. 2026-01-24 13:25:26 +08:00
395920743b 更新类库,应用联网验证模块有改进。 2026-01-24 13:23:22 +08:00
25f4c79860 <winboll>APK 15.11.11 release Publish. 2026-01-23 06:00:53 +08:00
5440c1ad39 整理调试菜单配置 2026-01-23 05:52:42 +08:00
47dd4698b8 更新应用介绍窗口 2026-01-23 05:46:09 +08:00
861ccb5832 移除命令行里的文件夹创建命令。 2026-01-19 18:00:33 +08:00
8b1f119e44 更新 WinBoLL工作目录为/sdcard/WinBoLLStudio。添加 bash终端命令。 2026-01-19 17:39:11 +08:00
c6495d1859 Termux 下 Gradle 编译 WinBoLL 项目测试成功。 2026-01-19 15:47:18 +08:00
15197b123c gradle命令调用成功 2026-01-19 15:21:06 +08:00
df2e91d390 Termux 终端显示功能实现。 2026-01-19 14:51:24 +08:00
61ca0d2672 Termux应用包命令调用成功。 2026-01-19 14:43:50 +08:00
8c18710e36 正在制作模块“发送Action 让Termux自行Bash命令。”。。。 2026-01-19 12:04:58 +08:00
224bd243e2 设置WinBoLL在Termux的工作目录。 2026-01-19 11:39:35 +08:00
b30bdc6802 添加Termux环境测试 2026-01-19 11:35:00 +08:00
8f0973cb6c 添加Termux环境测试窗口 2026-01-19 11:24:07 +08:00
b9fab2d737 <winboll>APK 15.11.10 release Publish. 2026-01-13 16:53:24 +08:00
156af54eaa 应用窗口切换调试完成 2026-01-13 16:52:01 +08:00
fb9dd93162 正在调整工具栏与应用介绍窗口。。。 2026-01-13 12:26:11 +08:00
7e757a456a <winboll>APK 15.11.9 release Publish. 2026-01-13 03:11:40 +08:00
43 changed files with 2571 additions and 1216 deletions

236
README.md
View File

@@ -1,175 +1,103 @@
## OriginMaster
【OriginMaster】WinBoLL 源生态计划。正如话,我需要一个 Point, 去撬动成个地球。
WinBoLL系列项目各个项目源码合并推送方向
WinBoLL=>APPBase=>OriginMaster
WinBoLL=>AES=>OriginMaster
WinBoLL=>PowerBell=>OriginMaster
WinBoLL=>Positions=>OriginMaster
仓库规划概述:
☆ WinBoLL,APPBase,AES,PowerBell与Positions都是开发库。
☆ OriginMaster 是分支汇总存档库。
☆ OriginMaster 不适宜作为开发库克隆使用,不是应用开发基础库,而是汇总资料库。
☆ WinBoLL 库可以作为应用开发的基础继承模板。
# WinBoLL 源生态计划项目说明书
########
## ☁ ☁ ☁ WinBoLL APP ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
# ☁ ☁ WinBoLL Studio Android 应用开源项目。☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
# ☁ ☁ ☁ WinBoLL 网站地址 https://www.winboll.cc/ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
# ☁ ☁ ☁ WinBoLL 源码地址 <https://gitea.winboll.cc/Studio/WinBoLL.git> ☁ ☁ ☁ ☁ ☁ ☁ ☁
# ☁ ☁ ☁ GitHub 源码地址 <https://github.com/ZhanGSKen/WinBoLL.git> ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
# ☁ ☁ ☁ 码云 源码地址 <https://gitee.com/zhangsken/winboll.git> ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
# ☁ ☁ ☁ 在 jitpack.io 托管的 APPBase 类库源码<https://github.com/ZhanGSKen/APPBase.git> ☁ ☁ ☁ ☁
# ☁ ☁ ☁ 在 jitpack.io 托管的 AES 类库源码<https://github.com/ZhanGSKen/AES.git> ☁ ☁ ☁ ☁
## WinBoLL 提问
同样是 /sdcard 目录,在开发 Android 应用时,
能否实现手机编译与电脑编译的源码同步。
☁因而 WinBoLL 项目组诞生了。
## 一、项目概述
## WinBoLL 项目组研发计划
致力于把 WinBoLL-APP 应用在手机端 Android 项目开发。
也在探索 https://gitea.winboll.cc/<WinBoLL 项目组>/APP.git 应用于 WinBoLL-APP APK 分发。
更想进阶 https://github.com/<WinBoLL 项目组>/APP.git 应用于 WinBoLL-APP Beta APK 分发。
### 1. 核心定位
WinBoLL 手机源码计划,旨在通过核心项目 WinBoLL 构建手机端与服务器端的 Android 项目的开发源码生态。实现手机与服务器的源码的联合开发。
## WinBoLL-APP 汗下...
#### ☁应用何置如此呢。且观用户云云。
### 2. 仓库架构
#### **仓库类型:功能说明**
☆ 基础项目分支 WinBoLL手机端安卓应用开发基础模板。
☆ 应用项目分支 APPBase、AES、PowerBell、Positions**:安卓应用单一管理系列项目。
☆ 源码汇总管理 OriginMaster**:各类分支源码合并存档,不适宜作为开发库使用。
#### ☁ 正当下 ☁ ###
#### ☁ 且容傻家叙说 ☁ WinBoLL-APP 应用场景
### ☁ WinBoLL 设备资源概述
#### ☁ 1. Raid Disk.
概述:这是一个矩阵存储类设备。
优点:该设备具有数据容错存储功能,
数据存储具有特长持久性。
缺点:设备使用能源消耗比较高,
设备存取速度一般。
#### ☁ 2. Data Disk.
概述:这是一个普通硬盘存储设备
优点:该设备独立于操作系统,
数据持久性一般,
存取能源消耗小于 Raid Disk。
缺点:数据存储速度一般,存储能源消耗一般。
### 3. 源码合并管理推送路线图
⚠️ **注意**:仅仅展示不同应用模块源码的综合管理路线。分支合并操作时,必须具备 Git 管理经验。
#### ☁ 3. SSD Disk.
概述:这是一个 SSD 硬盘存储设备。
优点:存取速度快于 Data Disk 与 Raid Disk
存取能源消耗小于 Data Disk 与 Raid Disk。
缺点:数据持久性一般,
设备位于操作系统内部文件系统。
数据持久性与操作系统挂钩。
#### ☁ 4. WinBoLL 用户资源概述。
1> /home/<用户名> 位于 WinBoLL 操作系统目录下。
2> /rdisk/<用户名> 挂载用户 Raid Disk.
3> /data/<用户名> 挂载用户 Data Disk.
4> /sdcard/<用户名> 挂载用户 SSD Disk.
★ WinBoLL → APPBase → OriginMaster
★ WinBoLL → AES → OriginMaster
★ WinBoLL → PowerBell → OriginMaster
★ WinBoLL → Positions → OriginMaster
#### ☁ 5. WinBoLL-APP 用户资源概述。
1> /sdcard 挂载用户手机 SD 存储/storage/emulated/0
## 二、WinBoLL 项目核心信息
### ☁ 稍稍歇 ☁ ###
### ☁ 急急停 ☁ WinBoLL 应用前置条件
☁ WinBoLL 主机建立 1Panel MySQL 应用。
☁ WinBoLL 主机建立 1Panel Gitea 应用。
☁ WinBoLL 主机设置 WinBoLL 应用为非登录状态。
☁ WinBoLL 主机建立 WinBoLL 账户与 WinBoLL 用户组。
☁ WinBoLL 账户 User ID 为: J。
☁ WinBoLL 用户组 Group ID 为: Studio。
☁ WinBoLL 主机 WinBoLL 1Panel Gitea 建立 WinBoLL 工作组。
☁ WinBoLL 主机 WinBoLL 1Panel Gitea 用户项目 APK 编译输出目录为 /sdcard/WinBoLLStudio/<用户名>/APKs/
☁ WinBoLL 项目配置文件示例为 "<WinBoLL 项目根目录>/.winboll/winboll.properties-demo"(WinBoLL 项目已设置)
☁ WinBoLL 项目配置文件为 "<WinBoLL 项目根目录>/.winboll/winboll.properties"
☁ WinBoLL 项目配置文件设定为源码提交时忽略。(WinBoLL 项目已设置)
☁ Gradle 项目配置文件示例为 "<WinBoLL 项目根目录>/.winboll/local.properties-demo"(WinBoLL 项目已设置)
☁ Gradle 项目配置文件为 "<WinBoLL 项目根目录>/local.properties"(WinBoLL 项目已设置)
☁ Gradle 项目配置文件设定为源码提交时忽略。(WinBoLL 项目已设置)
### 1. 项目简介
☆ WinBoLL 项目是为手机端开发Android 项目的需求而设计的项目。
### ☁ 登高处 ☁ WinBoLL 应用需求规划
☁ WinBoLL 主机建立 WinBoLL 客户端用户数据库为 MySQL winbollclient 数据库。
☁ WinBoLL 主机设置 WinBoLL 客户端用户信息存储在 winbollclient 数据库中。
☁ MySQL winbollclient 数据库中
WinBoLL 客户端用户信息设定为:
<用户名, 验证密码, 验证邮箱, 验证手机, 唯一存储令牌Token, 备用验证邮箱>
☁ WinBoLL 项目源码仓库托管在 WinBoLL 1Panel Gitea 目录 /opt/1panel/apps/gitea/gitea/data/git/repositories/studio/app.git中。
☁ WinBoLL 主机提供 WinBoLL 1Panel Gitea 应用的 WinBoLL 项目源码仓库存取功能。Gitea 应用已提供)
☁ WinBoLL 主机提供 WinBoLL Gitea 项目仓库存档功能。Gitea 应用已提供)
☁ 提供 WinBoLL 客户端用户登录功能。Gitea 应用已提供)
### 2. 官方资源
#### ☆ 官方网站**https://www.winboll.cc/
#### ☆ 源码地址:
★ Giteahttps://gitea.winboll.cc/Studio/WinBoLL.git
★ GitHubhttps://github.com/ZhanGSKen/WinBoLL.git
★ 码云https://gitee.com/zhangsken/winboll.git
### ☁ 看远方 ☁ ###
### ☁ 心忧虑 ☁ WinBoLL-APP 应用前置需求
☁ WinBoLL-APP WinBoLL 项目根目录设定为手机的 /sdcard/WinBoLLStudio/Sources 目录。(需要用户手动建立文件夹)
☁ WinBoLL-APP 具有手机 /sdcard/WinBoLL 目录的存储权限。(需要手机操作系统授权)
☁ WinBoLL-APP WinBoLL 项目仓库源码存储路径为 /sdcard/WinBoLLStudio/Sources/APP.git需要用户手动建立文件夹
☁ WinBoLL-APP 项目 APK 编译输出目录为 /sdcard/WinBoLLStudio/APKs/
☁ WinBoLL-APP 应用签名验证可定制化。WinBoLL 项目已提供)
☁ WinBoLL-APP 与系列衍生 APP 应用共享 cc.winboll.studio 命名空间资源。WinBoLL 项目已提供)
☁ WinBoLL-APP 用户客户端信息存储在命名空间为 WinBoLL APP MySQLLite 应用的 winbollappclient 数据库中。
☁ WinBoLL-APP MySQLLite 应用的 winbollappclient 数据库中,
WinBoLL 用户客户端信息设定为:
<用户名, 唯一存储令牌Token>
## 三、应用编译环境检查问题
### 核心判断条件:
WinBoLL 项目以文件夹 `"/sdcard/WinBoLLStudio/APKs"` 是否存在为判断环境编译输出条件因为编译输出的APK文件需要一个可供保存的环境。
### ☁ 云游四方 ☁ ###
### ☁ 呔! ☁ WinBoLL-APP 应用需求规划
☁ 如要使用 WinBoLL Android 项目的 Gradle 编译功能,则需要设置以下两个文件夹。
☁ 1. 则需要建立数据存储目录 /sdcard/WinBoLLStudio/APKs。
WinBoLL 项目源码编译出来的安装包会拷贝一份到 /sdcard/WinBoLLStudio/APKs 目录下。
☁ 2. 则需要建立数据存储目录 /sdcard/AppProjects。
WinBoLL 项目源码编译出来的安装包会拷贝一份并命名 "app.apk" 的安装文件为到 /sdcard/AppProjects 目录下。
☆ 文件夹"/sdcard/WinBoLLStudio/APKs" 目录条件设置方法:
***Linux 服务器端方面***:建立 `/sdcard/WinBoLLStudio/APKs` 目录即可。
***手机开发端方面***:建立 `"/sdcard/WinBoLLStudio/APKs"` 目录(即 `"/storage/emulated/0/WinBoLLStudio/APKs"` 目录) 即可
## 四、前置条件
### ☁ 吁! ☁ WinBoLL-APP 共享计划前景
WinBoLL-APP 将会实现 https://winboll.cc/api 访问功能。
☁ WinBoLL-APP 将会实现手机端 Android 应用的开发与管理功能
### 1. WinBoLL APP 开发环境配置介绍
#### WinBoLL APK 编译输出内容包括:
☆ "/sdcard/WinBoLLStudio/APKs"` 目录内的所有应用分支的 APK 文件
☆ "/sdcard/AppProjects/app.apk"文件。
#### WinBoLL APK 源码命名空间规范
☆ WinBoLL 项目使用 "cc.winboll.studio" 作为源码命名空间。在此命名空间下进行源码定义。
## ☁ WinBoLL ☁ WinBoLL 主机忧虑
☁ WinBoLL 将会提供 gitea.winboll.cc 域名用户注册登录功能。
☁ WinBoLL 将会提供 WinBoLL-APP 及其衍生应用的 Gitea 仓库管理服务。
☁ WinBoLL 将会提供 winboll.cc 域名 WinBoLL 项目组注册登录功能。
## 五、核心需求规划
# 本项目要实际运用需要注意以下几个步骤:
# 在项目根目录下:
## ★. 项目模块编译环境设置(必须)settings.gradle-demo 要复制为 settings.gradle并取消相应项目模块的注释。
## ★. 项目模块编译环境设置(必须) 在根目录拷贝 gradle.properties-androidx-demo 或者 gradle.properties-android-demo 文件为 gradle.properties。
## ★. 项目 Android SDK 编译环境设置(可选)local.properties-demo 要复制为 local.properties并按需要设置 Android SDK 目录。
## ★. 应用签名密钥 keystore 设置问题。一般调试编译只需用【Termux】cd 进 GenKeyStore 目录执行 $ bash gen_debug_keystore.sh 命令即可完成设置。
## ☆. 应用 WiBoLL 签名密钥配置问题<非必须考虑>。设置时需要 clone 【keystore】模块源码并拷贝模块目录的 appkey.jks 与 appkey.keystore 到项目根目录即可。
## ☆. 类库型模块编译环境设置(可选)winboll.properties-demo 要复制为 winboll.properties并按需要设置 WinBoLL Maven 库登录用户信息, 和 APK 文件额外输出路径。
### 1. WinBoLL 应用安全验证需求
#### ☆ 支持访问 https://console.winboll.cc/ 服务器以校验应用包签名与版本。
### 2. 手机端源码开发管理需求
#### ☆ 支持切换不同 WinBoLL 分支,以开发不同安卓应用。
# ☆类库型项目编译方法
## 先编译类库对应的模块测试项目
### 修改模块测试项目的 build.properties 文件
设置属性 libraryProject=<类库项目模块文件夹名称>
### 再编译测试项目
$ bash .winboll/bashPublishAPKAddTag.sh <应用项目模块文件夹名称>
#### 测试项目编译后,编译器会复制一份 APK 到 路径:"/sdcard/WinBoLLStudio/APKs/<项目根目录名称>/tag/" 文件夹。
#### 若是 winboll.properties 文件的 [ExtraAPKOutputPath] 属性设置了路径。编译器也会复制一份 APK 到这个路径。
### 最后编译类库项目
$ bash .winboll/bashPublishLIBAddTag.sh <类库项目模块文件夹名称>
#### 类库模块编译命令执行后,编译器会发布到 WinBoLL Nexus Maven 库Maven 库地址可以参阅根项目目录配置 build.gradle 文件。
# ☆应用型项目编译方法
## 直接调用以下命令编译应用型项目
$ bash .winboll/bashPublishAPKAddTag.sh <应用项目模块文件夹名称>
#### 应用模块编译命令执行后,编译器会复制一份 APK 到
#### 测试项目编译后,编译器会复制一份 APK 到 路径:"/sdcard/WinBoLLStudio/APKs/<项目根目录名称>/tag/" 文件夹。
#### 若是 winboll.properties 文件的 [ExtraAPKOutputPath] 属性设置了路径。编译器也会复制一份 APK 到这个路径。
## 六、编译与使用指南
## ☆应用调试编译方法
使用以下命令编译调试:
### 1. 项目初始化(必须)
#### 1. 复制 `settings.gradle-demo` 为 `settings.gradle`。编辑 `settings.gradle` 文件内容,取消对应项目模块注释。
#### 2. 复制 `gradle.properties-androidx-demo` (Android X 项目) 或 `gradle.properties-android-demo` (基本 Android 项目) 为 `gradle.properties`。
#### 3. 复制(可选)`local.properties-demo` 为 `local.properties`,编辑 `local.properties` 文件内容,配置 Android SDK 目录。
#### 4. **签名设置**
☆ **调试编译秘钥制作**:使用 Termux 应用终端cd 进入 GenKeyStore 目录,运行 `bash gen_debug_keystore.sh` 脚本即可生成应用调试秘钥。
☆ **应用秘钥配置方法**:拷贝调试编译秘钥制作生成的 `appkey.jks` 与 `appkey.keystore` 文件到项目根目录即可。
### Beta调试使用
$ bash gradlew assembleBetaDebug
## 七、应用编译命令介绍
### Stage调试使用
$ bash gradlew assembleStageDebug
### 1类库型模块配置要点
#### 1. **优先修改配置文件**:优先修改应用测试项目(目录为 `"<WinBoLl根目录>/<类库测试应用>/"`)内 `build.properties` 文件,设置对应的类库项目名称:`libraryProject=<类库项目模块名>`。
#### 2. **编译优先启动步骤**:使用 Termux 应用,进入 `"<WinBoLl根目录>"`,运行 `$ bash .winboll/bashPublishAPKAddTag.sh <类库测试项目模块名>` 命令。运行后可生成测试项目与类库项目的编译参数文件 `build.properties`。生成的 `build.properties` 文件有两份,一份在测试项目模块的文件夹内,一份在类库项目本身的模块文件夹内。
#### 3. **最后类库编译发布步骤**:使用 Termux 应用,进入 `"<WinBoLl根目录>"`,运行 `$ bash .winboll/bashPublishLIBAddTag.sh <类库项目模块名>` 命令。运行后可发布至 WinBoLL Nexus Maven 库、本地 maven 目录或者是通用默认的 Gradle Maven 库。
### 若是 winboll.properties 文件的 [ExtraAPKOutputPath] 属性设置了路径。编译器也会复制一份 APK 到这个路径。
### 2单一应用型模块与类库测试型模块配置要点
#### ☆ APK 编译方法:
使用 Termux 应用,进入 `"<WinBoLl根目录>"`,运行 `$ bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名>`。
#### ☆ 运行后的 APK 输出路径:
★ 默认路径 (`$ bash gradlew assembleBetaDebug` 任务)APK 在 `/sdcard/WinBoLLStudio/APKs/<项目根目录名称>/debug/` 目录。
★ 默认路径 (`$ bash assembleStageRelease` 任务)APK 在 `/sdcard/WinBoLLStudio/APKs/<项目根目录名称>/tag/` 目录。
★ 额外输出路径:(假设 `winboll.properties` 文件已配置 `ExtraAPKOutputPath` 属性) 输出至 `ExtraAPKOutputPath` 属性配置的目录下。
# 应用版本号命名方式
## statge 渠道
V<应用开发环境编号><应用功能变更号><应用调试阶段号>
APPBase_15.7.0
## beta 渠道
V<应用开发环境编号><应用功能变更号><应用调试阶段号>-beta<调试编译计数>_<调试编译时间(分钟+秒钟)>
APPBase_15.9.6-beta8_5413
### 3手机端应用调试命令介绍
#### ☆ Beta 渠道调试命令
$bash gradlew assembleBetaDebug
#### ☆ Stage 渠道调试命令
$bash gradlew assembleStageDebug
### 4服务器端开发命令介绍
##### ☆ Stage 渠道应用发布命令为:
"<WinBoLl根目录>/settings.gradle"文件需要配置编译模块开启参数,拷贝 settings.gradle-demo 为 settings.gradle 文件取消对应的分支配置部分即可。)
$bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名> 
或者是
$bash gradlew assembleStageRelease
## 八、WinBoLL 应用 APK 版本号命名规则
### ☆ Stage 渠道:
#### V<应用开发环境编号><应用功能变更号><应用调试阶段号> 示例 APPBase_15.7.0 
### ☆ Beta 渠道:
#### V<应用开发环境编号><应用功能变更号><应用调试阶段号>-beta<调试编译计数>_<调试编译时间(分钟+秒钟)> 示例 APPBase_15.9.6-beta8_5413 

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sat Jan 24 19:51:55 HKT 2026
stageCount=11
#Wed Mar 25 20:36:14 HKT 2026
stageCount=15
libraryProject=libappbase
baseVersion=15.15
publishVersion=15.15.10
publishVersion=15.15.14
buildCount=0
baseBetaVersion=15.15.11
baseBetaVersion=15.15.15

View File

@@ -10,6 +10,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Toolbar;
import cc.winboll.studio.appbase.R;
import cc.winboll.studio.appbase.model.TestBean;
import cc.winboll.studio.libappbase.LogActivity;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
@@ -36,13 +37,28 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ToastUtils.show("onCreate"); // 显示 Activity 创建提示(调试用)
//ToastUtils.show("onCreate"); // 显示 Activity 创建提示(调试用)
setContentView(R.layout.activity_main); // 加载主界面布局
// 初始化 Toolbar 并设置为 ActionBar
mToolbar = findViewById(R.id.toolbar);
setActionBar(mToolbar); // 将 Toolbar 替代系统默认 ActionBar
initTestData();
}
void initTestData() {
TestBean bean1 = new TestBean();
bean1.setTestNum1(456);
TestBean.saveBeanToFile(getFilesDir().getAbsolutePath() + getTestBeanRelativePath(), bean1);
TestBean bean2 = new TestBean();
bean2.setTestNum1(789);
TestBean.saveBeanToFile(getExternalFilesDir(null).getAbsolutePath() + getTestBeanRelativePath(), bean2);
}
String getTestBeanRelativePath() {
return "/BaseBaen/"+TestBean.class.getName()+".json";
}
/**
* 创建菜单时回调(加载工具栏菜单)
@@ -136,12 +152,11 @@ public class MainActivity extends Activity {
// 启动意图(唤起浏览器)
context.startActivity(intent);
}
public void onAboutActivity(View view) {
LogUtils.d(TAG, "startAboutActivity() 调用");
LogUtils.d(TAG, "onAboutActivity() 调用");
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
startActivity(aboutIntent);
LogUtils.d(TAG, "startAboutActivity: 关于页面已启动");
}
}

View File

@@ -0,0 +1,154 @@
package cc.winboll.studio.appbase.model;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import cc.winboll.studio.libappbase.LogUtils;
import java.io.IOException;
/**
* 测试实体类
* 继承BaseBean实现JSON序列化/反序列化能力提供基础int类型属性的封装与数据持久化支持
* 适配Java7语法遵循BaseBean统一的反射识别、JSON读写规范
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/31 19:16:00
* @LastEditTime 2026/02/01 10:46:00
*/
public class TestBean extends BaseBean {
// ====================================== 常量定义 ======================================
/** 当前类的日志 TAG用于调试输出 */
public static final String TAG = "TestBean";
// ====================================== 成员属性 ======================================
/**
* 测试数字属性默认值123
* 基础int类型属性用于测试BaseBean的JSON序列化/反序列化能力
*/
private int testNum1;
// ====================================== 构造方法 ======================================
/**
* 无参构造器(默认初始化)
* 给testNum1赋值默认值123满足反射实例化、JSON解析的无参构造要求
*/
public TestBean() {
this.testNum1 = 123;
LogUtils.d(TAG, "TestBean无参构造器调用testNum1默认初始化值" + this.testNum1);
}
/**
* 有参构造器(自定义初始化)
* @param testNum1 测试数字初始值
*/
public TestBean(int testNum1) {
this.testNum1 = testNum1;
LogUtils.d(TAG, "TestBean有参构造器调用传入testNum1" + testNum1);
}
// ====================================== Get/Set 方法 ======================================
/**
* 设置测试数字属性值
* @param testNum1 待设置的int类型值
*/
public void setTestNum1(int testNum1) {
LogUtils.d(TAG, "setTestNum1调用传入参数" + testNum1);
this.testNum1 = testNum1;
}
/**
* 获取测试数字属性值
* @return 当前testNum1的int类型值
*/
public int getTestNum1() {
LogUtils.d(TAG, "getTestNum1调用返回值" + this.testNum1);
return testNum1;
}
// ====================================== 重写父类BaseBean方法 ======================================
/**
* 重写父类方法:获取当前类的全限定名
* 用于BaseBean反射识别、类名匹配等统一逻辑
* @return 类全限定名cc.winboll.studio.appbase.model.TestBean
*/
@Override
public String getName() {
LogUtils.d(TAG, "getName方法调用返回类全限定名" + TestBean.class.getName());
return TestBean.class.getName();
}
/**
* 重写父类方法将当前对象序列化为JSON持久化存储专用
* 遵循BaseBean规范先执行父类序列化逻辑再处理子类专属字段
* @param jsonWriter JSON写入器外部传入的JSON流操作实例
* @throws IOException JSON写入异常流关闭、格式错误等
*/
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
LogUtils.d(TAG, "writeThisToJsonWriter调用传入参数JsonWriter" + jsonWriter);
// 执行父类公共字段的序列化逻辑
super.writeThisToJsonWriter(jsonWriter);
// 序列化子类专属字段testNum1
jsonWriter.name("testNum1").value(this.getTestNum1());
LogUtils.d(TAG, "writeThisToJsonWriter执行完成已序列化testNum1" + this.getTestNum1());
}
/**
* 重写父类方法从JSON字段初始化当前对象属性解析JSON专用
* 先让父类处理公共字段再匹配子类专属字段不匹配则返回false跳过
* @param jsonReader JSON读取器外部传入的JSON流操作实例
* @param name 当前解析的JSON字段名
* @return true-字段解析成功false-字段不匹配,需跳过/父类处理
* @throws IOException JSON读取异常字段类型不匹配、流中断等
*/
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
LogUtils.d(TAG, "initObjectsFromJsonReader调用传入参数name=" + name + "JsonReader=" + jsonReader);
// 父类优先处理公共字段,处理成功则直接返回
if (super.initObjectsFromJsonReader(jsonReader, name)) {
LogUtils.d(TAG, "initObjectsFromJsonReader字段" + name + "由父类BaseBean处理成功");
return true;
}
// 解析子类专属字段
if ("testNum1".equals(name)) {
this.setTestNum1(jsonReader.nextInt());
LogUtils.d(TAG, "initObjectsFromJsonReader解析testNum1成功值为" + this.getTestNum1());
} else {
LogUtils.w(TAG, "initObjectsFromJsonReader字段" + name + "不匹配返回false跳过解析");
// 字段不匹配返回false表示跳过
return false;
}
return true;
}
/**
* 重写父类方法从JSON读取器完整解析并初始化当前对象JSON解析入口
* 负责JSON对象的开始/结束标识处理,遍历所有字段并调用字段解析方法
* 严格遵循writeThisToJsonWriter的序列化结构保证解析一致性
* @param jsonReader JSON读取器外部传入的JSON流操作实例
* @return 解析后的当前TestBean实例支持链式调用
* @throws IOException JSON解析异常格式错误、字段缺失、流异常等
*/
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
LogUtils.d(TAG, "readBeanFromJsonReader调用传入参数JsonReader" + jsonReader);
// 开始解析JSON对象与序列化结构保持一致
jsonReader.beginObject();
// 遍历所有JSON字段
while (jsonReader.hasNext()) {
String fieldName = jsonReader.nextName();
LogUtils.d(TAG, "readBeanFromJsonReader开始解析字段fieldName=" + fieldName);
// 解析字段,不匹配则跳过该值
if (!this.initObjectsFromJsonReader(jsonReader, fieldName)) {
jsonReader.skipValue();
LogUtils.w(TAG, "readBeanFromJsonReader字段" + fieldName + "解析失败,已跳过该值");
}
}
// 结束JSON对象解析必须调用避免流异常
jsonReader.endObject();
LogUtils.d(TAG, "readBeanFromJsonReader执行完成JSON解析结束当前TestBean实例testNum1" + this.getTestNum1());
// 返回当前实例,支持链式调用
return this;
}
}

View File

@@ -70,7 +70,7 @@
android:layout_marginHorizontal="24dp"
android:onClick="onAboutActivity"
android:layout_margin="10dp"/>
</LinearLayout>
</ScrollView>

View File

@@ -27,5 +27,8 @@ dependencies {
api 'com.google.code.gson:gson:2.8.9'
// Html 解析
api 'org.jsoup:jsoup:1.13.1'
// 添加JSch依赖SFTP核心com.jcraft:jsch:0.1.54
api 'com.jcraft:jsch:0.1.54'
api fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sat Jan 24 19:51:55 HKT 2026
stageCount=11
#Wed Mar 25 20:36:14 HKT 2026
stageCount=15
libraryProject=libappbase
baseVersion=15.15
publishVersion=15.15.10
publishVersion=15.15.14
buildCount=0
baseBetaVersion=15.15.11
baseBetaVersion=15.15.15

View File

@@ -14,10 +14,10 @@
<!-- MANAGE_EXTERNAL_STORAGE -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<application
android:requestLegacyExternalStorage="true"
android:networkSecurityConfig="@xml/network_security_config">
android:requestLegacyExternalStorage="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".CrashHandler$CrashActivity"
@@ -44,6 +44,8 @@
<activity android:name="cc.winboll.studio.libappbase.activities.NfcRsaLoginActivity"/>
<activity android:name="cc.winboll.studio.libappbase.activities.FTPBackupsActivity"/>
</application>
</manifest>
</manifest>

View File

@@ -0,0 +1,101 @@
package cc.winboll.studio.libappbase.models;
/**
* SFTP登录验证信息实体类
* 封装SFTP登录所需的所有配置信息服务端地址、端口、账号密码、秘钥信息、编码
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/30 19:08:00
* @LastEditTime 2026/01/31 22:45:00
*/
public class SFTPAuthModel {
public static final String TAG = "SFTPAuthModel";
// SFTP服务器地址必填如192.168.1.100、sftp.xxx.com
private String ftpServer;
// SFTP服务器端口必填默认22
private int ftpPort = 22;
// SFTP登录用户名匿名登录传null/空)
private String ftpUsername;
// SFTP登录密码匿名登录传null/空)
private String ftpPassword;
// SFTP登录秘钥路径秘钥登录时使用本地绝对路径如/sdcard/sftp/key.pem账号密码登录传null/空)
private String ftpKeyPath;
// SFTP登录秘钥密码秘钥有密码时填写无密码传null/空)
private String ftpKeyPwd;
// SFTP编码默认UTF-8解决中文文件名乱码
private String ftpCharset = "UTF-8";
// 空参构造JavaBean规范
public SFTPAuthModel() {
}
// 全参构造(快速初始化)
public SFTPAuthModel(String ftpServer, int ftpPort, String ftpUsername, String ftpPassword,
String ftpKeyPath, String ftpKeyPwd, String ftpCharset) {
this.ftpServer = ftpServer;
this.ftpPort = ftpPort;
this.ftpUsername = ftpUsername;
this.ftpPassword = ftpPassword;
this.ftpKeyPath = ftpKeyPath;
this.ftpKeyPwd = ftpKeyPwd;
this.ftpCharset = ftpCharset;
}
// ==================== Get/Set 方法 ====================
public String getFtpServer() {
return ftpServer;
}
public void setFtpServer(String ftpServer) {
this.ftpServer = ftpServer;
}
public int getFtpPort() {
return ftpPort;
}
public void setFtpPort(int ftpPort) {
this.ftpPort = ftpPort;
}
public String getFtpUsername() {
return ftpUsername;
}
public void setFtpUsername(String ftpUsername) {
this.ftpUsername = ftpUsername;
}
public String getFtpPassword() {
return ftpPassword;
}
public void setFtpPassword(String ftpPassword) {
this.ftpPassword = ftpPassword;
}
public String getFtpKeyPath() {
return ftpKeyPath;
}
public void setFtpKeyPath(String ftpKeyPath) {
this.ftpKeyPath = ftpKeyPath;
}
public String getFtpKeyPwd() {
return ftpKeyPwd;
}
public void setFtpKeyPwd(String ftpKeyPwd) {
this.ftpKeyPwd = ftpKeyPwd;
}
public String getFtpCharset() {
return ftpCharset;
}
public void setFtpCharset(String ftpCharset) {
this.ftpCharset = ftpCharset;
}
}

View File

@@ -2,6 +2,9 @@ package cc.winboll.studio.libappbase.utils;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import cc.winboll.studio.libappbase.LogUtils;
@@ -13,78 +16,67 @@ import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2026-01-24 10:00:00
* @LastEditTime 2026-01-24 19:50:00
* @Describe 客户端签名工具类与服务端APKFileUtils签名/哈希校验逻辑严格对齐纯Java7实现直接读取APK内签名文件计算保证校验一致性
* @LastEditTime 2026-01-24 22:00:00
* @Describe 客户端签名工具类与服务端APKFileUtils签名/哈希校验逻辑严格对齐纯Java7实现兼容MT重签名遍历META-INF所有RSA文件增加PackageManager兜底方案
*/
public class ApkSignUtils {
// ===================================== 全局常量定义 =====================================
private static final String TAG = "ApkSignUtils";
// APK内签名文件路径兼容大小写
private static final String CERT_RSA_UPPER = "META-INF/CERT.RSA";
private static final String CERT_RSA_LOWER = "META-INF/cert.rsa";
// 加密算法常量
private static final String ALGORITHM_SHA1 = "SHA1";
private static final String ALGORITHM_SHA256 = "SHA-256";
// 缓冲区大小常量(按业务场景区分)
private static final int BUFFER_4K = 4096;
private static final int BUFFER_8K = 8192;
// 签名文件目录与后缀
private static final String META_INF_DIR = "META-INF/";
private static final String RSA_SUFFIX_UPPER = ".RSA";
private static final String RSA_SUFFIX_LOWER = ".rsa";
// ===================================== 对外核心方法 =====================================
/**
* 获取与服务端对齐的签名Base64串
* 逻辑:读取APK内CERT.RSA原始字节 → SHA1摘要 → Base64.NO_WRAP编码,与服务端完全一致
* @param context 上下文用于获取当前应用APK的真实安装路径
* 获取与服务端对齐的签名Base64串兼容MT重签名
* 优先逻辑:遍历APK内META-INF所有.RSA文件 → 读取第一个有效文件原始字节 → SHA1摘要 → Base64.NO_WRAP
* 兜底逻辑PackageManager获取系统解析的签名 → SHA1摘要 → Base64.NO_WRAP
* @param context 上下文用于获取当前应用APK路径/包信息
* @return 签名Base64字符串任意步骤失败返回null
*/
public static String getApkSignAlignedWithServer(Context context) {
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方法调用,开始执行服务端对齐签名计算");
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方法调用,开始执行服务端对齐签名计算兼容MT重签名");
// 入参空值快速校验
if (context == null) {
LogUtils.w(TAG, "getApkSignAlignedWithServer: 入参context为null直接返回null");
return null;
}
try {
// 1. 获取当前应用APK真实路径
ApplicationInfo appInfo = context.getApplicationContext().getApplicationInfo();
String apkPath = appInfo.sourceDir;
LogUtils.d(TAG, "getApkSignAlignedWithServer: 成功获取APK路径path=" + apkPath);
if (apkPath == null || apkPath.trim().isEmpty()) {
LogUtils.e(TAG, "getApkSignAlignedWithServer: 获取到的APK路径为空无法读取签名文件");
return null;
}
// 2. 读取APK内CERT.RSA原始字节流
byte[] certRawBytes = readCertRsaRawBytes(apkPath);
if (certRawBytes == null || certRawBytes.length == 0) {
LogUtils.e(TAG, "getApkSignAlignedWithServer: 读取CERT.RSA原始字节失败字节数组为空");
return null;
}
LogUtils.d(TAG, "getApkSignAlignedWithServer: 成功读取CERT.RSA字节长度=" + certRawBytes.length);
// 3. SHA1摘要 + Base64编码服务端对齐核心步骤
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA1);
byte[] signDigest = md.digest(certRawBytes);
String signBase64 = Base64.encodeToString(signDigest, Base64.NO_WRAP);
LogUtils.d(TAG, "getApkSignAlignedWithServer: 服务端对齐签名计算完成成功返回Base64串");
// 方案1优先读取APK内META-INF目录下所有RSA文件兼容MT重签名任意命名
String signBase64 = getSignFromApkRsaFile(context);
if (signBase64 != null) {
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方案1成功APK内读取RSA文件返回签名Base64");
return signBase64;
} catch (NoSuchAlgorithmException e) {
LogUtils.e(TAG, "getApkSignAlignedWithServer: 获取SHA1算法实例失败", e);
} catch (Exception e) {
LogUtils.e(TAG, "getApkSignAlignedWithServer: 计算服务端对齐签名发生未知异常", e);
}
// 方案2兜底 - PackageManager获取系统解析的应用签名避免APK文件读取失败
signBase64 = getSignFromPackageManager(context);
if (signBase64 != null) {
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方案2成功PackageManager兜底返回签名Base64");
return signBase64;
}
// 所有方案失败
LogUtils.e(TAG, "getApkSignAlignedWithServer: 所有签名获取方案均失败");
return null;
}
/**
* 获取当前运行APK的SHA256哈希值
* 获取当前运行APK的SHA256哈希值兼容重签名APK
* 逻辑读取APK完整文件字节流 → SHA256摘要 → 转小写64位16进制字符串服务端同款校验逻辑
* @param context 上下文用于获取当前应用APK的真实安装路径
* @return SHA256小写16进制字符串任意步骤失败返回null
@@ -97,6 +89,8 @@ public class ApkSignUtils {
return null;
}
JarFile jarFile = null;
FileInputStream fis = null;
try {
// 1. 获取当前应用APK真实路径
ApplicationInfo appInfo = context.getApplicationContext().getApplicationInfo();
@@ -107,16 +101,15 @@ public class ApkSignUtils {
return null;
}
// 2. 读取APK文件并计算SHA256哈希
// 2. 读取APK文件并计算SHA256哈希(完善流关闭)
File apkFile = new File(apkPath);
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA256);
FileInputStream fis = new FileInputStream(apkFile);
fis = new FileInputStream(apkFile);
byte[] buffer = new byte[BUFFER_8K];
int readLen;
while ((readLen = fis.read(buffer)) != -1) {
md.update(buffer, 0, readLen);
}
fis.close();
LogUtils.d(TAG, "getApkSHA256Hash: APK文件读取完成开始转换哈希结果");
// 3. 哈希字节数组转小写64位16进制字符串
@@ -133,50 +126,127 @@ public class ApkSignUtils {
LogUtils.e(TAG, "getApkSHA256Hash: 获取SHA-256算法实例失败", e);
} catch (Exception e) {
LogUtils.e(TAG, "getApkSHA256Hash: 计算APK SHA256哈希发生未知异常", e);
} finally {
// 强制关闭流避免重签名APK解析的流泄漏
try {
if (fis != null) fis.close();
if (jarFile != null) jarFile.close();
} catch (IOException e) {
LogUtils.e(TAG, "getApkSHA256Hash: 关闭流资源异常", e);
}
}
return null;
}
// ===================================== 内部工具方法 =====================================
// ===================================== 内部核心工具方法(兼容重签名) =====================================
/**
* 读取APK内CERT.RSA文件的原始字节流兼容大小写命
* @param apkPath APK文件的完整绝对路径
* @return CERT.RSA原始字节数组未找到文件返回null
* @throws Exception 流读取、APK解析相关异常向上抛出
* 方案1遍历APK内META-INF所有.RSA/.rsa文件读取第一个有效文件计算签
* @param context 上下文
* @return 签名Base64失败返回null
*/
private static byte[] readCertRsaRawBytes(String apkPath) throws Exception {
LogUtils.d(TAG, "readCertRsaRawBytes: 方法调用开始读取APK内签名文件apkPath=" + apkPath);
JarFile jarFile = new JarFile(apkPath);
JarEntry certEntry = null;
private static String getSignFromApkRsaFile(Context context) {
JarFile jarFile = null;
InputStream is = null;
try {
// 获取APK路径
ApplicationInfo appInfo = context.getApplicationContext().getApplicationInfo();
String apkPath = appInfo.sourceDir;
if (apkPath == null || apkPath.trim().isEmpty()) {
LogUtils.w(TAG, "getSignFromApkRsaFile: APK路径为空跳过该方案");
return null;
}
// 优先读取大写命名,不存在则尝试小写
certEntry = jarFile.getJarEntry(CERT_RSA_UPPER);
if (certEntry == null) {
LogUtils.d(TAG, "readCertRsaRawBytes: 未找到META-INF/CERT.RSA尝试读取小写META-INF/cert.rsa");
certEntry = jarFile.getJarEntry(CERT_RSA_LOWER);
}
// 打开APK的JarFile
jarFile = new JarFile(apkPath);
Enumeration<JarEntry> entries = jarFile.entries();
JarEntry targetRsaEntry = null;
// 未找到有效签名文件关闭流后返回null
if (certEntry == null) {
LogUtils.e(TAG, "readCertRsaRawBytes: APK内未找到CERT.RSA/cert.rsa签名文件");
jarFile.close();
// 遍历所有条目找到META-INF下第一个.RSA/.rsa文件
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
// 过滤META-INF目录下 + 以.RSA/.rsa结尾 + 非目录
if (entryName.startsWith(META_INF_DIR) && !entry.isDirectory()
&& (entryName.endsWith(RSA_SUFFIX_UPPER) || entryName.endsWith(RSA_SUFFIX_LOWER))) {
targetRsaEntry = entry;
LogUtils.d(TAG, "getSignFromApkRsaFile: 找到有效签名文件name=" + entryName);
break; // 取第一个有效RSA文件即可
}
}
// 未找到任何RSA文件
if (targetRsaEntry == null) {
LogUtils.w(TAG, "getSignFromApkRsaFile: 未在META-INF找到任何.RSA/.rsa签名文件");
return null;
}
// 读取RSA文件原始字节
is = jarFile.getInputStream(targetRsaEntry);
byte[] certRawBytes = readStreamToBytes(is);
if (certRawBytes == null || certRawBytes.length == 0) {
LogUtils.w(TAG, "getSignFromApkRsaFile: 读取RSA文件字节为空");
return null;
}
// 计算SHA1+Base64
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA1);
byte[] signDigest = md.digest(certRawBytes);
return Base64.encodeToString(signDigest, Base64.NO_WRAP);
} catch (Exception e) {
LogUtils.e(TAG, "getSignFromApkRsaFile: 从APK内读取RSA文件失败", e);
return null;
} finally {
// 强制关闭所有流
try {
if (is != null) is.close();
if (jarFile != null) jarFile.close();
} catch (IOException e) {
LogUtils.e(TAG, "getSignFromApkRsaFile: 关闭流资源异常", e);
}
}
// 读取文件原始字节并关闭所有流资源
InputStream is = jarFile.getInputStream(certEntry);
byte[] certBytes = readStreamToBytes(is);
is.close();
jarFile.close();
LogUtils.d(TAG, "readCertRsaRawBytes: 签名文件读取完成,字节长度=" + certBytes.length);
return certBytes;
}
/**
* 输入流转字节数组,通用工具方法
* 4K缓冲区适配小文件读取如CERT.RSA保证流资源正常关闭
* 方案2兜底 - 通过PackageManager获取系统解析的应用签名
* 避免APK文件读取失败如权限、解析问题兼容所有重签名场景
* @param context 上下文
* @return 签名Base64失败返回null
*/
private static String getSignFromPackageManager(Context context) {
try {
// 获取当前应用包信息(包含签名)
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
if (packageInfo == null || packageInfo.signatures == null || packageInfo.signatures.length == 0) {
LogUtils.w(TAG, "getSignFromPackageManager: 未获取到应用签名信息");
return null;
}
// 取第一个签名(重签名后一般只有一个签名)
Signature signature = packageInfo.signatures[0];
byte[] signBytes = signature.toByteArray();
// 计算SHA1+Base64与服务端逻辑对齐
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA1);
byte[] signDigest = md.digest(signBytes);
return Base64.encodeToString(signDigest, Base64.NO_WRAP);
} catch (PackageManager.NameNotFoundException e) {
LogUtils.e(TAG, "getSignFromPackageManager: 包名未找到,无法获取签名", e);
} catch (NoSuchAlgorithmException e) {
LogUtils.e(TAG, "getSignFromPackageManager: 获取SHA1算法实例失败", e);
} catch (Exception e) {
LogUtils.e(TAG, "getSignFromPackageManager: PackageManager获取签名失败", e);
}
return null;
}
/**
* 输入流转字节数组通用工具方法完善try-finally
* 4K缓冲区适配小文件读取如RSA签名文件保证流资源正常关闭
* @param is 待读取的输入流
* @return 转换后的字节数组流为null返回空字节数组
* @return 转换后的字节数组流为null/读取失败返回空字节数组
* @throws IOException 流读取相关异常向上抛出
*/
private static byte[] readStreamToBytes(InputStream is) throws IOException {
@@ -187,14 +257,16 @@ public class ApkSignUtils {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[BUFFER_4K];
int readLen;
while ((readLen = is.read(buffer)) != -1) {
bos.write(buffer, 0, readLen);
try {
while ((readLen = is.read(buffer)) != -1) {
bos.write(buffer, 0, readLen);
}
return bos.toByteArray();
} finally {
// 强制关闭所有流
is.close();
bos.close();
}
byte[] result = bos.toByteArray();
// 关闭流资源,避免内存泄漏
is.close();
bos.close();
return result;
}
}

View File

@@ -0,0 +1,305 @@
package cc.winboll.studio.libappbase.utils;
import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.models.SFTPAuthModel;
/**
* 文件备份工具类(单例模式)
* 区分应用Data目录/应用专属外部文件目录双Map管理备份文件路径
* 核心功能:文件添加/移除 + ZIP打包分data/sdcard目录 + SFTP分步式上传登录→传输→登出
* 依赖FTPUtils单例、SFTPAuthModel外部实体类、Android上下文
* 兼容Java7、Android 6.0+无第三方依赖ZIP为原生实现免动态读写权限
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/30 20:18:00
* @LastEditTime 2026/02/01 02:05:00
*/
public class BackupUtils {
public static final String TAG = "BackupUtils";
// ZIP内部分级目录常量统一维护便于修改
private static final String ZIP_DIR_DATA = "data/";
private static final String ZIP_DIR_SDCARD = "sdcard/";
// 单例实例双重校验锁volatile保证可见性线程安全
private static volatile BackupUtils sInstance;
// 双Map分目录管理key=文件唯一标识value=对应目录下的相对路径
private final Map<String, String> mDataDirFileMap; // 基础根目录应用私有Data目录(/data/data/[包名]/files)
private final Map<String, String> mSdcardFileMap; // 基础根目录:应用专属外部文件目录(/storage/emulated/0/Android/data/[包名]/files)
// 全局上下文持有Application上下文避免Activity内存泄漏
private Context mAppContext;
// SFTP认证配置直接引用外部实体类无内部封装
private SFTPAuthModel mFtpAuthModel;
// SFTP服务器指定上传目录独立参数传入标准化后作为成员变量
private String mFtpTargetDir;
// 应用专属外部文件目录SDCard Map的基础根目录初始化时赋值避免重复创建
private File mAppExternalFilesDir;
// 私有构造器新增双Map入参空值则使用内部默认初始化非空则用入参初始化
private BackupUtils(Context context, SFTPAuthModel ftpAuthModel, String ftpTargetDir,
Map<String, String> dataDirFileMap, Map<String, String> sdcardFileMap) {
this.mAppContext = context.getApplicationContext();
this.mFtpAuthModel = ftpAuthModel;
// 初始化SDCard Map的基础根目录应用专属外部文件目录/storage/emulated/0/Android/data/[包名]/files
this.mAppExternalFilesDir = mAppContext.getExternalFilesDir(null);
// 标准化SFTP上传目录空则默认/,非空则补全结尾斜杠
this.mFtpTargetDir = TextUtils.isEmpty(ftpTargetDir) ? "/" : (ftpTargetDir.endsWith("/") ? ftpTargetDir : ftpTargetDir + "/");
// 核心修改入参Map非空且非空集合时使用入参初始化否则内部new HashMap()
this.mDataDirFileMap = (dataDirFileMap != null && !dataDirFileMap.isEmpty())
? new HashMap<>(dataDirFileMap) // 新建Map避免外部篡改内部数据
: new HashMap<>();
this.mSdcardFileMap = (sdcardFileMap != null && !sdcardFileMap.isEmpty())
? new HashMap<>(sdcardFileMap) // 深拷贝,隔离外部引用
: new HashMap<>();
LogUtils.d(TAG, "BackupUtils初始化完成 → SFTP服务器" + ftpAuthModel.getFtpServer() + ":" + ftpAuthModel.getFtpPort() + " | 上传目录:" + mFtpTargetDir);
LogUtils.d(TAG, "SDCard Map基础根目录" + (mAppExternalFilesDir == null ? "获取失败" : mAppExternalFilesDir.getAbsolutePath()));
LogUtils.d(TAG, "初始化后DataMap大小" + mDataDirFileMap.size() + " | SdcardMap大小" + mSdcardFileMap.size());
}
/**
* 单例初始化方法必须先调用否则getInstance()会抛异常)
* 新增双Map入参支持外部初始化待备份文件列表
* @param context 上下文推荐传Application避免内存泄漏
* @param ftpAuthModel 外部SFTP认证实体类含服务器/账号/端口等)
* @param ftpTargetDir SFTP服务器指定上传目录如/backup自动补全斜杠
* @param dataDirFileMap 外部传入的Data目录文件Mapnull/空则内部默认初始化
* @param sdcardFileMap 外部传入的SDCard目录文件Mapnull/空则内部默认初始化
* @return BackupUtils单例实例
*/
public static BackupUtils getInstance(Context context, SFTPAuthModel ftpAuthModel, String ftpTargetDir,
Map<String, String> dataDirFileMap, Map<String, String> sdcardFileMap) {
if (sInstance == null) {
synchronized (BackupUtils.class) {
if (sInstance == null) {
// 前置强校验:避免空参数导致后续空指针
if (context == null) {
throw new IllegalArgumentException("初始化失败Context 不能为空");
}
if (ftpAuthModel == null || TextUtils.isEmpty(ftpAuthModel.getFtpServer())) {
throw new IllegalArgumentException("初始化失败SFTPAuthModel/ftpServer 不能为空");
}
// 透传新增的双Map入参至构造器
sInstance = new BackupUtils(context, ftpAuthModel, ftpTargetDir, dataDirFileMap, sdcardFileMap);
}
}
}
return sInstance;
}
/**
* 重载默认初始化方法兼容原有调用逻辑无需传入Map内部默认初始化
* 避免修改后影响原有代码调用
*/
public static BackupUtils getInstance(Context context, SFTPAuthModel ftpAuthModel, String ftpTargetDir) {
return getInstance(context, ftpAuthModel, ftpTargetDir, null, null);
}
/**
* 获取单例实例需先调用带参getInstance初始化
* @return BackupUtils单例实例
*/
public static BackupUtils getInstance() {
if (sInstance == null) {
throw new IllegalStateException("BackupUtils未初始化请先调用getInstance(Context, SFTPAuthModel, String[, Map, Map])");
}
return sInstance;
}
// ====================================== 以下原有方法均未修改 ======================================
public void addDataDirFile(String key, String relativePath) {
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(relativePath)) {
mDataDirFileMap.put(key, relativePath);
LogUtils.d(TAG, "添加Data目录文件" + key + "" + relativePath);
}
}
public void removeDataDirFile(String key) {
if (!TextUtils.isEmpty(key) && mDataDirFileMap.containsKey(key)) {
mDataDirFileMap.remove(key);
LogUtils.d(TAG, "移除Data目录文件" + key);
}
}
public String getDataDirFile(String key) {
return mDataDirFileMap.get(key);
}
public Map<String, String> getAllDataDirFiles() {
return new HashMap<>(mDataDirFileMap);
}
public void clearDataDirFiles() {
mDataDirFileMap.clear();
LogUtils.d(TAG, "清空Data目录所有备份文件");
}
public void addSdcardFile(String key, String relativePath) {
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(relativePath) && mAppExternalFilesDir != null) {
mSdcardFileMap.put(key, relativePath);
LogUtils.d(TAG, "添加外部文件目录文件:" + key + "" + relativePath);
}
}
public void removeSdcardFile(String key) {
if (!TextUtils.isEmpty(key) && mSdcardFileMap.containsKey(key)) {
mSdcardFileMap.remove(key);
LogUtils.d(TAG, "移除外部文件目录文件:" + key);
}
}
public String getSdcardFile(String key) {
return mSdcardFileMap.get(key);
}
public Map<String, String> getAllSdcardFiles() {
return new HashMap<>(mSdcardFileMap);
}
public void clearSdcardFiles() {
mSdcardFileMap.clear();
LogUtils.d(TAG, "清空外部文件目录所有备份文件");
}
public boolean packAndUploadByFtp() {
if (mDataDirFileMap.isEmpty() && mSdcardFileMap.isEmpty()) {
LogUtils.e(TAG, "SFTP上传失败无待备份文件DataDir+外部文件目录均为空)");
return false;
}
if (mAppExternalFilesDir == null) {
LogUtils.e(TAG, "SFTP上传失败应用专属外部文件目录获取失败无法访问文件");
return false;
}
String zipFileName = UUID.randomUUID().toString().replace("-", "")
+ "-" + System.currentTimeMillis() + ".zip";
File tempZipFile = new File(mAppContext.getExternalCacheDir(), zipFileName);
String remoteFtpFilePath = mFtpTargetDir + zipFileName;
FTPUtils ftpUtils = FTPUtils.getInstance();
boolean isUploadSuccess = false;
try {
LogUtils.d(TAG, "开始SFTP登录" + mFtpAuthModel.getFtpServer() + ":" + mFtpAuthModel.getFtpPort());
boolean isFtpLogin = ftpUtils.login(mFtpAuthModel);
if (!isFtpLogin) {
LogUtils.e(TAG, "SFTP上传失败SFTP登录失败账号/密码/服务器/端口错误)");
return false;
}
LogUtils.i(TAG, "SFTP登录成功准备打包文件" + zipFileName);
LogUtils.d(TAG, "开始本地ZIP打包分data/sdcard目录临时文件路径" + tempZipFile.getAbsolutePath());
boolean isPackSuccess = packFilesToZip(tempZipFile);
if (!isPackSuccess || !tempZipFile.exists() || tempZipFile.length() == 0) {
LogUtils.e(TAG, "SFTP上传失败ZIP打包失败文件不存在/空文件)");
return false;
}
LogUtils.i(TAG, "ZIP打包成功文件大小" + tempZipFile.length() / 1024 + "KB");
LogUtils.d(TAG, "开始SFTP上传本地→SFTP" + remoteFtpFilePath);
isUploadSuccess = ftpUtils.uploadFile(tempZipFile.getAbsolutePath(), remoteFtpFilePath);
if (isUploadSuccess) {
LogUtils.i(TAG, "SFTP上传全流程成功" + remoteFtpFilePath);
} else {
LogUtils.e(TAG, "SFTP上传失败文件传输到服务器失败响应码异常/权限不足)");
}
} catch (Exception e) {
LogUtils.e(TAG, "SFTP上传异常" + e.getMessage(), e);
isUploadSuccess = false;
} finally {
if (ftpUtils.isConnected()) {
ftpUtils.logout();
}
ftpUtils.disconnect();
if (tempZipFile.exists()) {
boolean isDelete = tempZipFile.delete();
LogUtils.d(TAG, "本地临时ZIP文件删除" + (isDelete ? "成功" : "失败"));
}
System.gc();
}
return isUploadSuccess;
}
private boolean packFilesToZip(File zipFile) {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new FileOutputStream(zipFile), Charset.forName("UTF-8"));
zos.setLevel(ZipOutputStream.DEFLATED);
if (!mDataDirFileMap.isEmpty()) {
packDirFilesToZip(zos, mDataDirFileMap, mAppContext.getFilesDir(), ZIP_DIR_DATA);
LogUtils.d(TAG, "Data目录文件已打包到ZIP→" + ZIP_DIR_DATA + "子目录");
}
if (!mSdcardFileMap.isEmpty() && mAppExternalFilesDir != null) {
packDirFilesToZip(zos, mSdcardFileMap, mAppExternalFilesDir, ZIP_DIR_SDCARD);
LogUtils.d(TAG, "应用专属外部文件目录文件已打包到ZIP→" + ZIP_DIR_SDCARD + "子目录");
}
zos.flush();
return true;
} catch (IOException e) {
LogUtils.e(TAG, "ZIP打包IO异常" + e.getMessage(), e);
return false;
} finally {
if (zos != null) {
try {
zos.close();
} catch (IOException e) {
LogUtils.e(TAG, "关闭ZIP流异常" + e.getMessage(), e);
}
}
}
}
private void packDirFilesToZip(ZipOutputStream zos, Map<String, String> fileMap, File baseDir, String zipSubDir) {
for (Map.Entry<String, String> entry : fileMap.entrySet()) {
String relativePath = entry.getValue();
if (TextUtils.isEmpty(relativePath)) {
continue;
}
File localFile = new File(baseDir, relativePath);
if (!localFile.exists() || !localFile.isFile()) {
LogUtils.w(TAG, "跳过无效文件:" + localFile.getAbsolutePath());
continue;
}
String zipInnerPath = zipSubDir + relativePath;
try {
addSingleFileToZip(zos, localFile, zipInnerPath);
} catch (IOException e) {
LogUtils.e(TAG, "打包单个文件失败:" + zipInnerPath, e);
}
}
}
private void addSingleFileToZip(ZipOutputStream zos, File localFile, String zipInnerPath) throws IOException {
ZipEntry zipEntry = new ZipEntry(zipInnerPath);
zos.putNextEntry(zipEntry);
FileInputStream fis = new FileInputStream(localFile);
byte[] buffer = new byte[4096];
int len;
while ((len = fis.read(buffer)) != -1) {
zos.write(buffer, 0, len);
}
fis.close();
zos.closeEntry();
}
}

View File

@@ -0,0 +1,487 @@
package cc.winboll.studio.libappbase.utils;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.models.SFTPAuthModel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.Vector;
/**
* SFTP/FTP工具类单例模式- Java7兼容 · 适配FTPAuthModel实体类
* 底层严格基于JSch 0.1.54原生ChannelSftp+SftpException接口实现替换原commons-net FTP
* 核心功能:登录/登出、文件上传/下载、文件夹列举、文件/文件夹存在性判断
* 依赖com.jcraft:jsch:0.1.54
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/30 19:04
*/
public class FTPUtils {
// 单例实例(双重校验锁 volatile 保证可见性Java7兼容
private static volatile FTPUtils sInstance;
// JSch核心对象Session连接会话、ChannelSftpSFTP通道
private JSch mJSch;
private Session mSession;
private ChannelSftp mSftpChannel;
// 日志TAG
public static final String TAG = "FTPUtils";
// SFTP默认端口FTPAuthModel未设置时使用
private static final int DEFAULT_SFTP_PORT = 22;
// 连接超时时间 5sJava7原生Socket超时
private static final int CONNECT_TIMEOUT = 5000;
// 私有构造器:禁止外部实例化
private FTPUtils() {
initSftpClient();
}
/**
* 获取单例实例双重校验锁线程安全Java7兼容
* @return FTPUtils 单例
*/
public static FTPUtils getInstance() {
if (sInstance == null) {
synchronized (FTPUtils.class) {
if (sInstance == null) {
sInstance = new FTPUtils();
}
}
}
return sInstance;
}
/**
* 初始化SFTP客户端JSch创建核心原生对象
*/
private void initSftpClient() {
if (mJSch == null) {
mJSch = new JSch();
LogUtils.d(TAG, "SFTP客户端JSch初始化完成");
}
// 重置会话和通道,避免连接残留
mSession = null;
mSftpChannel = null;
}
/**
* 【推荐】SFTP登录基于FTPAuthModel实体类完全兼容原有参数
* @param ftpAuthModel 登录配置实体类不能为空端口默认22编码默认UTF-8
* @return 登录成功返回true失败false
*/
public boolean login(SFTPAuthModel ftpAuthModel) {
// 1. 实体类非空校验
if (ftpAuthModel == null) {
LogUtils.e(TAG, "SFTP登录失败FTPAuthModel实体类为null");
return false;
}
// 2. 核心参数校验(服务器地址不能为空)
if (isParamEmpty(ftpAuthModel.getFtpServer())) {
LogUtils.e(TAG, "SFTP登录失败服务器地址ftpServer不能为空");
return false;
}
// 3. 若已连接,先断开
if (isConnected()) {
logout();
}
// 4. 重新初始化客户端
initSftpClient();
try {
// 获取服务器地址、端口默认22、账号、密码
String host = ftpAuthModel.getFtpServer();
int port = ftpAuthModel.getFtpPort() <= 0 ? DEFAULT_SFTP_PORT : ftpAuthModel.getFtpPort();
String username = ftpAuthModel.getFtpUsername();
String password = ftpAuthModel.getFtpPassword();
// SFTP不支持匿名登录账号密码不能为空原生接口无匿名登录能力
if (isParamEmpty(username) || isParamEmpty(password)) {
LogUtils.e(TAG, "SFTP登录失败SFTP不支持匿名登录请配置有效账号密码");
return false;
}
// 1. 创建JSch会话原生接口
mSession = mJSch.getSession(username, host, port);
mSession.setPassword(password);
// 2. 设置会话属性跳过SSH密钥校验适配大部分服务器
Properties sessionProps = new Properties();
sessionProps.put("StrictHostKeyChecking", "no");
sessionProps.put("PreferredAuthentications", "password");
mSession.setConfig(sessionProps);
// 3. 设置会话连接超时原生接口底层Socket超时
mSession.setTimeout(CONNECT_TIMEOUT);
// 4. 建立会话连接(原生接口)
mSession.connect();
LogUtils.d(TAG, "SFTP会话连接成功" + host + ":" + port);
// 5. 打开SFTP通道类型sftp原生接口强转
mSftpChannel = (ChannelSftp) mSession.openChannel("sftp");
mSftpChannel.connect();
// 6. 设置文件名编码解决中文乱码ChannelSftp原生接口
String charset = isParamEmpty(ftpAuthModel.getFtpCharset()) ? "UTF-8" : ftpAuthModel.getFtpCharset();
mSftpChannel.setFilenameEncoding(charset);
LogUtils.d(TAG, "SFTP文件名编码设置成功" + charset);
LogUtils.i(TAG, "SFTP登录成功服务器" + host + ":" + port + ",用户名:" + username);
return true;
} catch (JSchException e) {
LogUtils.e(TAG, "SFTP登录JSch异常" + e.getMessage(), e);
logout();
return false;
} catch (SftpException e) {
// 匹配SftpException原生属性和方法
LogUtils.e(TAG, "SFTP通道初始化异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
logout();
return false;
}
}
/**
* 【已废弃】原FTP多参数登录方法适配JSch后保留推荐使用login(FTPAuthModel)
* @deprecated 请使用基于FTPAuthModel的登录方法
*/
@Deprecated
public boolean login(String host, int port, String username, String password) {
SFTPAuthModel ftpAuthModel = new SFTPAuthModel();
ftpAuthModel.setFtpServer(host);
ftpAuthModel.setFtpPort(port <= 0 ? DEFAULT_SFTP_PORT : port);
ftpAuthModel.setFtpUsername(username);
ftpAuthModel.setFtpPassword(password);
return login(ftpAuthModel);
}
/**
* SFTP登出并断开连接释放所有资源严格调用原生disconnect接口
* @return 登出成功返回true失败false
*/
public boolean logout() {
boolean isSuccess = true;
// 关闭SFTP通道原生接口disconnect非空判断即可
if (mSftpChannel != null) {
try {
mSftpChannel.disconnect();
LogUtils.d(TAG, "SFTP通道已断开");
} catch (Exception e) {
LogUtils.e(TAG, "关闭SFTP通道异常" + e.getMessage(), e);
isSuccess = false;
}
}
// 关闭JSch会话原生接口disconnect非空判断即可
if (mSession != null) {
try {
mSession.disconnect();
LogUtils.d(TAG, "SFTP会话已断开");
} catch (Exception e) {
LogUtils.e(TAG, "关闭SFTP会话异常" + e.getMessage(), e);
isSuccess = false;
}
}
// 重置客户端,避免资源残留
initSftpClient();
if (isSuccess) {
LogUtils.i(TAG, "SFTP登出成功");
} else {
LogUtils.w(TAG, "SFTP登出失败部分资源未正常释放");
}
return isSuccess;
}
/**
* 强制断开连接兜底资源释放同logout方法
*/
public void disconnect() {
logout();
}
/**
* 判断SFTP是否已连接会话+通道均调用原生isConnected接口
* @return 已连接返回true否则false
*/
public boolean isConnected() {
return mSession != null && mSession.isConnected()
&& mSftpChannel != null && mSftpChannel.isConnected();
}
/**
* 上传文件到SFTP指定路径覆盖式上传调用ChannelSftp原生put接口OVERWRITE模式
* @param localFilePath 本地文件绝对路径(如/sdcard/test.apk
* @param remoteFilePath SFTP服务器目标路径如/ftp/apk/test.apk需包含文件名
* @return 上传成功返回true失败false
*/
public boolean uploadFile(String localFilePath, String remoteFilePath) {
// 前置校验
if (!isConnected()) {
LogUtils.e(TAG, "文件上传失败SFTP未连接服务器");
return false;
}
if (isParamEmpty(localFilePath) || isParamEmpty(remoteFilePath)) {
LogUtils.e(TAG, "文件上传失败:本地/远程路径不能为空");
return false;
}
File localFile = new File(localFilePath);
if (!localFile.exists() || !localFile.isFile()) {
LogUtils.e(TAG, "文件上传失败:本地文件不存在/非文件,路径:" + localFilePath);
return false;
}
InputStream fis = null;
try {
// 自动创建远程多级目录基于原生mkdir/stat接口
createRemoteDir(remoteFilePath);
// 读取本地文件上传到SFTP原生put接口OVERWRITE覆盖模式
fis = new FileInputStream(localFile);
mSftpChannel.put(fis, remoteFilePath, ChannelSftp.OVERWRITE);
LogUtils.i(TAG, "文件上传成功:本地" + localFilePath + " → 远程" + remoteFilePath);
return true;
} catch (IOException e) {
LogUtils.e(TAG, "文件上传IO异常" + e.getMessage(), e);
return false;
} catch (SftpException e) {
// 严格匹配SftpException原生属性id、getMessage()、toString()
LogUtils.e(TAG, "文件上传SFTP异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
return false;
} finally {
// 关闭流资源,避免内存泄漏
closeStream(fis, null);
}
}
/**
* 从SFTP下载文件到本地指定路径覆盖式下载调用ChannelSftp原生get接口
* @param remoteFilePath SFTP服务器文件路径如/ftp/apk/test.apk
* @param localFilePath 本地目标路径(如/sdcard/test.apk需包含文件名
* @return 下载成功返回true失败false
*/
public boolean downloadFile(String remoteFilePath, String localFilePath) {
// 前置校验
if (!isConnected()) {
LogUtils.e(TAG, "文件下载失败SFTP未连接服务器");
return false;
}
if (isParamEmpty(remoteFilePath) || isParamEmpty(localFilePath)) {
LogUtils.e(TAG, "文件下载失败:远程/本地路径不能为空");
return false;
}
// 校验远程文件是否存在基于ChannelSftp原生stat接口
if (!isFileExists(remoteFilePath)) {
LogUtils.e(TAG, "文件下载失败:远程文件不存在,路径:" + remoteFilePath);
return false;
}
OutputStream fos = null;
try {
// 创建本地多级目录
File localFile = new File(localFilePath);
File parentDir = localFile.getParentFile();
if (!parentDir.exists() && !parentDir.mkdirs()) {
LogUtils.e(TAG, "文件下载失败:创建本地目录失败,路径:" + parentDir.getAbsolutePath());
return false;
}
// 从SFTP读取文件写入本地原生get接口
fos = new FileOutputStream(localFile);
mSftpChannel.get(remoteFilePath, fos);
LogUtils.i(TAG, "文件下载成功:远程" + remoteFilePath + " → 本地" + localFilePath);
return true;
} catch (IOException e) {
LogUtils.e(TAG, "文件下载IO异常" + e.getMessage(), e);
// 删除未下载完成的本地文件
new File(localFilePath).delete();
return false;
} catch (SftpException e) {
// 严格匹配SftpException原生属性id、getMessage()、toString()
LogUtils.e(TAG, "文件下载SFTP异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
// 删除未下载完成的本地文件
new File(localFilePath).delete();
return false;
} finally {
// 关闭流资源,避免内存泄漏
closeStream(null, fos);
}
}
/**
* 列举SFTP指定文件夹下的所有文件/文件夹返回ChannelSftp原生Vector过滤.和..
* @param remoteDir SFTP服务器目录路径如/ftp/apk/,结尾带/或不带均可)
* @return 成功返回原生Vector<ChannelSftp.LsEntry>失败返回空Vector
*/
@SuppressWarnings("rawtypes")
public Vector listDir(String remoteDir) {
Vector fileList = new Vector();
// 前置校验
if (!isConnected()) {
LogUtils.e(TAG, "列举目录失败SFTP未连接服务器");
return fileList;
}
if (isParamEmpty(remoteDir)) {
LogUtils.e(TAG, "列举目录失败:远程目录路径不能为空");
return fileList;
}
// 校验目录是否存在基于ChannelSftp原生stat接口
if (!isDirExists(remoteDir)) {
LogUtils.e(TAG, "列举目录失败:远程目录不存在,路径:" + remoteDir);
return fileList;
}
try {
// 列举目录下所有文件/文件夹调用ChannelSftp原生ls接口返回原生Vector
Vector vector = mSftpChannel.ls(remoteDir);
if (vector != null && vector.size() > 0) {
for (Object obj : vector) {
// 过滤.和..上级目录,仅保留有效文件/目录
ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) obj;
String fileName = entry.getFilename();
if (!".".equals(fileName) && !"..".equals(fileName)) {
fileList.add(obj);
}
}
}
LogUtils.i(TAG, "列举目录成功:" + remoteDir + ",共" + fileList.size() + "个文件/文件夹");
} catch (SftpException e) {
// 严格匹配SftpException原生属性id、getMessage()、toString()
LogUtils.e(TAG, "列举目录SFTP异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
}
return fileList;
}
/**
* 判断SFTP服务器上**文件**是否存在基于ChannelSftp原生stat接口匹配SftpException原生异常
* @param remoteFilePath SFTP服务器文件路径如/ftp/apk/test.apk
* @return 存在且为文件返回true否则false
*/
public boolean isFileExists(String remoteFilePath) {
// 前置校验
if (!isConnected()) {
LogUtils.e(TAG, "判断文件存在性失败SFTP未连接服务器");
return false;
}
if (isParamEmpty(remoteFilePath)) {
LogUtils.e(TAG, "判断文件存在性失败:远程文件路径不能为空");
return false;
}
try {
// 调用ChannelSftp原生stat接口获取属性不存在会抛出SSH_FX_NO_SUCH_FILE异常
SftpATTRS attrs = mSftpChannel.stat(remoteFilePath);
// 原生isReg()判断是否为文件
return attrs.isReg();
} catch (SftpException e) {
// 仅匹配原生异常码SSH_FX_NO_SUCH_FILE(2):文件/目录不存在,不记错误日志
if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) {
LogUtils.e(TAG, "判断文件存在性SFTP异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
}
return false;
}
}
/**
* 判断SFTP服务器上**文件夹**是否存在基于ChannelSftp原生stat接口匹配SftpException原生异常
* @param remoteDir SFTP服务器目录路径如/ftp/apk/,结尾带/或不带均可)
* @return 存在且为目录返回true否则false
*/
public boolean isDirExists(String remoteDir) {
// 前置校验
if (!isConnected()) {
LogUtils.e(TAG, "判断目录存在性失败SFTP未连接服务器");
return false;
}
if (isParamEmpty(remoteDir)) {
LogUtils.e(TAG, "判断目录存在性失败:远程目录路径不能为空");
return false;
}
try {
// 调用ChannelSftp原生stat接口获取属性不存在会抛出SSH_FX_NO_SUCH_FILE异常
SftpATTRS attrs = mSftpChannel.stat(remoteDir);
// 原生isDir()判断是否为目录
return attrs.isDir();
} catch (SftpException e) {
// 仅匹配原生异常码SSH_FX_NO_SUCH_FILE(2):文件/目录不存在,不记错误日志
if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) {
LogUtils.e(TAG, "判断目录存在性SFTP异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
}
return false;
}
}
// ===================================== 内部工具方法(仅调用原生接口) =====================================
/**
* 递归创建SFTP远程多级目录基于ChannelSftp原生mkdir/stat接口不存在则创建
* @param remoteFilePath SFTP远程文件路径/目录路径
*/
private void createRemoteDir(String remoteFilePath) {
if (!isConnected()) {
LogUtils.e(TAG, "创建远程目录失败SFTP未连接服务器");
return;
}
try {
// 提取目录路径(文件路径→目录路径,目录路径直接使用)
String remoteDir = remoteFilePath.lastIndexOf("/") > 0
? remoteFilePath.substring(0, remoteFilePath.lastIndexOf("/"))
: remoteFilePath;
// 按/分割多级目录,递归创建(避免多级目录不存在)
String[] dirs = remoteDir.split("/");
StringBuilder currentDir = new StringBuilder();
for (String dir : dirs) {
if (isParamEmpty(dir)) {
continue;
}
currentDir.append("/").append(dir);
String dirPath = currentDir.toString();
// 目录不存在则调用ChannelSftp原生mkdir创建
if (!isDirExists(dirPath)) {
mSftpChannel.mkdir(dirPath);
LogUtils.d(TAG, "创建SFTP远程目录成功" + dirPath);
}
}
} catch (SftpException e) {
// 严格匹配SftpException原生属性id、getMessage()、toString()
LogUtils.e(TAG, "创建远程目录SFTP异常id=" + e.id + "msg=" + e.getMessage() + "detail=" + e.toString());
}
}
/**
* 关闭流资源通用工具方法Java7原生IO避免内存泄漏
* @param is 输入流可为null
* @param os 输出流可为null
*/
private void closeStream(InputStream is, OutputStream os) {
if (is != null) {
try {
is.close();
} catch (IOException e) {
LogUtils.e(TAG, "关闭输入流异常:" + e.getMessage(), e);
}
}
if (os != null) {
try {
os.close();
} catch (IOException e) {
LogUtils.e(TAG, "关闭输出流异常:" + e.getMessage(), e);
}
}
}
/**
* 判断参数是否为空null/空字符串/全空格Java7原生字符串操作
* @param param 待判断参数
* @return 为空返回true否则false
*/
private boolean isParamEmpty(String param) {
return param == null || param.trim().isEmpty();
}
}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp" android:color="#007AFF"/>
<corners android:radius="8dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp" android:color="#E5E5E5"/>
<corners android:radius="8dp"/>
</shape>
</item>
</selector>

View File

@@ -13,6 +13,9 @@ WinBoLL 网站浏览器。
阶段版编译命令 bash .winboll/bashPublishAPKAddTag.sh winboll
#### 使用说明
3. Termux应用配置
- 已安装Termux包名 com.termux 
- 执行  echo "allow-external-apps = true" > ~/.termux/termux.properties
#### 参与贡献

View File

@@ -73,12 +73,13 @@ dependencies {
implementation 'com.alibaba:fastjson:1.2.76'
// AndroidX 类库
api 'androidx.appcompat:appcompat:1.1.0'
/*api 'androidx.appcompat:appcompat:1.1.0'
//api 'com.google.android.material:material:1.4.0'
//api 'androidx.viewpager:viewpager:1.0.0'
//api 'androidx.vectordrawable:vectordrawable:1.1.0'
//api 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
//api 'androidx.fragment:fragment:1.1.0'
//api 'androidx.fragment:fragment:1.1.0'*/
// 米盟
api 'com.miui.zeus:mimo-ad-sdk:5.3.+'//请使用最新版sdk
@@ -88,14 +89,31 @@ dependencies {
api 'com.google.code.gson:gson:2.8.5'
api 'com.github.bumptech.glide:glide:4.9.0'
//annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation "androidx.annotation:annotation:1.3.0"
implementation "androidx.core:core:1.6.0"
implementation "androidx.drawerlayout:drawerlayout:1.1.1"
implementation "androidx.preference:preference:1.1.1"
implementation "androidx.viewpager:viewpager:1.0.0"
implementation "com.google.android.material:material:1.4.0"
implementation "com.google.guava:guava:24.1-jre"
/*
implementation "io.noties.markwon:core:$markwonVersion"
implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
implementation "io.noties.markwon:linkify:$markwonVersion"
implementation "io.noties.markwon:recycler:$markwonVersion"
*/
implementation 'com.termux:terminal-emulator:0.118.0'
implementation 'com.termux:terminal-view:0.118.0'
implementation 'com.termux:termux-shared:0.118.0'
// WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libaes:15.12.13'
api 'cc.winboll.studio:libappbase:15.14.2'
api 'cc.winboll.studio:libaes:15.15.2'
api 'cc.winboll.studio:libappbase:15.15.11'
// WinBoLL备用库 jitpack.io 地址
//api 'com.github.ZhanGSKen:AES:aes-v15.12.9'
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.14.1'
//api 'com.github.ZhanGSKen:AES:aes-v15.15.7'
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.15.4'
api fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Jan 12 05:14:13 GMT 2026
stageCount=9
#Mon Mar 16 19:52:21 GMT 2026
stageCount=26
libraryProject=
baseVersion=15.11
publishVersion=15.11.8
buildCount=15
baseBetaVersion=15.11.9
publishVersion=15.11.25
buildCount=29
baseBetaVersion=15.11.26

View File

@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.winboll.studio.winboll">
package="cc.winboll.studio.winboll"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="com.termux">
<!-- 拥有完全的网络访问权限 -->
<uses-permission android:name="android.permission.INTERNET"/>
@@ -11,6 +13,11 @@
<!-- 对正在运行的应用重新排序 -->
<uses-permission android:name="android.permission.REORDER_TASKS"/>
<!-- Android 11+ 查询已安装应用权限 -->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<!-- 可选:兼容低版本系统 -->
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<application
android:allowBackup="true"
@@ -282,6 +289,20 @@
<activity android:name="cc.winboll.studio.winboll.activities.WXPayActivity"/>
<activity android:name="cc.winboll.studio.winboll.unittest.TermuxEnvTestActivity"/>
<activity
android:name=".termux.NfcTermuxBridgeActivity"
android:exported="true"> <!-- 必须设置为 true允许外部应用调用 -->
<!-- 接收 ACTION_BUILD 意图 -->
<intent-filter>
<action android:name="cc.winboll.studio.winboll.termux.NfcTermuxBridgeActivity.ACTION_BUILD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
</manifest>

View File

@@ -1,53 +0,0 @@
package cc.winboll.studio.winboll;
/**
* @Author ZhanGSKen<zhangsken@188.com>
* @Date 2025/05/22 13:08
*/
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
public class CustomToolbar extends Toolbar {
private View viewMain;
public CustomToolbar(Context context) {
this(context, null);
}
public CustomToolbar(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context, attrs);
}
private void initView(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomToolbar);
// 获取属性值
String toolbarTitle = typedArray.getString(R.styleable.CustomToolbar_toolbarTitle);
int toolbarTitleColor = typedArray.getColor(R.styleable.CustomToolbar_toolbarTitleColor, android.graphics.Color.WHITE);
int toolbarBackgroundColor = typedArray.getColor(R.styleable.CustomToolbar_toolbarBackgroundColor, android.graphics.Color.BLUE);
// 加载布局
viewMain = LayoutInflater.from(context).inflate(R.layout.view_toolbar, this, true);
// 应用属性值
TextView toolbarTitleTextView = viewMain.findViewById(R.id.toolbar_title);
toolbarTitleTextView.setText(toolbarTitle);
toolbarTitleTextView.setTextColor(toolbarTitleColor);
viewMain.setBackgroundColor(toolbarBackgroundColor);
// 释放 TypedArray
typedArray.recycle();
}
}

View File

@@ -8,16 +8,15 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import cc.winboll.studio.libaes.activitys.AboutActivity;
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
import cc.winboll.studio.libaes.models.APPInfo;
import cc.winboll.studio.libaes.models.DrawerMenuBean;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.winboll.R;
import cc.winboll.studio.winboll.activities.AboutActivity;
import cc.winboll.studio.winboll.activities.SettingsActivity;
import cc.winboll.studio.winboll.activities.WXPayActivity;
import cc.winboll.studio.winboll.fragments.BrowserFragment;
import cc.winboll.studio.winboll.unittest.TermuxEnvTestActivity;
import java.util.ArrayList;
public class MainActivity extends DrawerFragmentActivity {
@@ -123,6 +122,9 @@ public class MainActivity extends DrawerFragmentActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.toolbar_main, menu);
if (App.isDebugging()) {
getMenuInflater().inflate(R.menu.toolbar_test, menu);
}
return super.onCreateOptionsMenu(menu);
}
@@ -149,12 +151,13 @@ public class MainActivity extends DrawerFragmentActivity {
}
} else if (nItemId == R.id.item_settings) {
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), SettingsActivity.class);
} else if (nItemId == R.id.item_wxpayactivity) {
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), WXPayActivity.class);
} else if (nItemId == cc.winboll.studio.libaes.R.id.item_about) {
} else if (nItemId == R.id.item_about) {
Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
APPInfo appInfo = genDefaultAPPInfo();
intent.putExtra(AboutActivity.EXTRA_APPINFO, appInfo);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else if (nItemId == R.id.item_termux_env_test) {
Intent intent = new Intent(getApplicationContext(), TermuxEnvTestActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else {
return super.onOptionsItemSelected(item);
@@ -163,23 +166,6 @@ public class MainActivity extends DrawerFragmentActivity {
return true;
}
APPInfo genDefaultAPPInfo() {
String szBranchName = "winboll";
APPInfo appInfo = new APPInfo();
appInfo.setAppName("WinBoLL");
appInfo.setAppIcon(cc.winboll.studio.libaes.R.drawable.ic_winboll);
appInfo.setAppDescription("WinBoLL 网站浏览器。");
appInfo.setAppGitName("WinBoLL");
appInfo.setAppGitOwner("Studio");
appInfo.setAppGitAPPBranch(szBranchName);
appInfo.setAppGitAPPSubProjectFolder(szBranchName);
appInfo.setAppHomePage("https://www.winboll.cc/apks/index.php?project=WinBoLL");
appInfo.setAppAPKName("WinBoLL");
appInfo.setAppAPKFolderName("WinBoLL");
return appInfo;
}
// ------------------- 新增对外提供Handler供其他组件发送消息如BrowserFragment -------------------
public Handler getMainHandler() {
return _mMainHandler;

View File

@@ -0,0 +1,86 @@
package cc.winboll.studio.winboll.activities;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.models.APPInfo;
import cc.winboll.studio.libappbase.views.AboutView;
import cc.winboll.studio.winboll.MainActivity;
import cc.winboll.studio.winboll.R;
import android.app.Activity;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/13 11:54
* @Describe 应用介绍窗口
*/
public class AboutActivity extends BaseWinBoLLActivity {
@Override
public Activity getActivity() {
return this;
}
public static final String TAG = "AboutActivity";
private Toolbar mToolbar;
@Override
public String getTag() {
return TAG;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
// 设置工具栏
initToolbar();
AboutView aboutView = getActivity().findViewById(R.id.aboutview);
aboutView.setAPPInfo(genDefaultAppInfo());
}
private void initToolbar() {
LogUtils.d(TAG, "initToolbar() 开始初始化");
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (mToolbar == null) {
LogUtils.e(TAG, "initToolbar() | Toolbar未找到");
return;
}
setSupportActionBar(mToolbar);
mToolbar.setSubtitle(getTag());
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtils.d(TAG, "导航栏 点击返回按钮");
getActivity().finish();
}
});
LogUtils.d(TAG, "initToolbar() 配置完成");
}
private APPInfo genDefaultAppInfo() {
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
String branchName = "winboll";
APPInfo appInfo = new APPInfo();
appInfo.setAppName(getActivity().getString(R.string.app_name));
appInfo.setAppIcon(R.drawable.ic_winboll);
appInfo.setAppDescription(getActivity().getString(R.string.app_description));
appInfo.setAppGitName("WinBoLL");
appInfo.setAppGitOwner("Studio");
appInfo.setAppGitAPPBranch(branchName);
appInfo.setAppGitAPPSubProjectFolder(branchName);
appInfo.setAppHomePage("https://www.winboll.cc/apks/index.php?project=WinBoLL");
appInfo.setAppAPKName("WinBoLL");
appInfo.setAppAPKFolderName("WinBoLL");
LogUtils.d(TAG, "genDefaultAppInfo: 应用信息已生成");
return appInfo;
}
}

View File

@@ -0,0 +1,56 @@
package cc.winboll.studio.winboll.activities;
import android.app.Activity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.models.AESThemeBean;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/13 16:33
* BaseWinBollActivity 【继承AppCompatActivity保留核心能力不额外暴露方法】
* 继承链路BaseWinBoLLActivity → AppCompatActivity → FragmentActivityAppCompat能力天然继承可用
*/
public abstract class BaseWinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {
public static final String TAG = "BaseWinBoLLActivity";
protected volatile AESThemeBean.ThemeType mThemeType;
@Override
protected void onCreate(Bundle savedInstanceState) {
mThemeType = getThemeType();
setThemeStyle();
super.onCreate(savedInstanceState);
WinBoLLActivityManager.getInstance().add(this);
//ToastUtils.show(getTag() + ": onCreate");
}
AESThemeBean.ThemeType getThemeType() {
/*SharedPreferences sharedPreferences = getSharedPreferences(
SHAREDPREFERENCES_NAME, MODE_PRIVATE);
return AESThemeBean.ThemeType.values()[((sharedPreferences.getInt(DRAWER_THEME_TYPE, AESThemeBean.ThemeType.DEFAULT.ordinal())))];
*/
return AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
}
void setThemeStyle() {
//setTheme(AESThemeBean.getThemeStyle(getThemeType()));
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
}
@Override
protected void onDestroy() {
WinBoLLActivityManager.getInstance().registeRemove(this);
super.onDestroy();
}
// 子类必须实现getTag(),确保唯一标识
@Override
public abstract String getTag();
public abstract Activity getActivity();
}

View File

@@ -5,20 +5,32 @@ package cc.winboll.studio.winboll.activities;
* @Date 2025/03/25 11:46:40
* @Describe 测试窗口2
*/
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toolbar;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.winboll.R;
import android.app.Activity;
public class New2Activity extends BaseWinBoLLActivity {
@Override
public Activity getActivity() {
return this;
}
public class New2Activity extends WinBoLLActivity {
public static final String TAG = "New2Activity";
Toolbar mToolbar;
@Override
public String getTag() {
return TAG;
}
//LogView mLogView;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -28,15 +40,10 @@ public class New2Activity extends WinBoLLActivity {
// mLogView = findViewById(R.id.logview);
// mLogView.start();
mToolbar = findViewById(R.id.toolbar);
setActionBar(mToolbar);
setSupportActionBar(mToolbar);
}
@Override
protected void onResume() {
super.onResume();
//mLogView.start();
}
public void onCloseThisActivity(View view) {
//WinBoLLActivityManager.getInstance().finish(this);
@@ -49,17 +56,4 @@ public class New2Activity extends WinBoLLActivity {
public void onNewActivity(View view) {
//WinBoLLActivityManager.getInstance().startWinBoLLActivity(this, NewActivity.class);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.toolbar_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// 在switch语句中处理每个ID并在处理完后返回true未处理的情况返回false。
return super.onOptionsItemSelected(item);
}
}

View File

@@ -5,29 +5,26 @@ package cc.winboll.studio.winboll.activities;
* @Date 2025/03/25 05:04:22
* @Describe
*/
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toolbar;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.winboll.R;
import cc.winboll.studio.winboll.App;
import android.app.Activity;
public class NewActivity extends BaseWinBoLLActivity {
@Override
public Activity getActivity() {
return this;
}
public class NewActivity extends WinBoLLActivity implements IWinBoLLActivity {
public static final String TAG = "NewActivity";
Toolbar mToolbar;
//LogView mLogView;
@Override
public Activity getActivity() {
return this;
}
@Override
public String getTag() {
return TAG;
@@ -40,15 +37,10 @@ public class NewActivity extends WinBoLLActivity implements IWinBoLLActivity {
// mLogView = findViewById(R.id.logview);
// mLogView.start();
mToolbar = findViewById(R.id.toolbar);
setActionBar(mToolbar);
setSupportActionBar(mToolbar);
}
@Override
protected void onResume() {
super.onResume();
//mLogView.start();
}
public void onCloseThisActivity(View view) {
WinBoLLActivityManager.getInstance().finish(this);
@@ -61,17 +53,4 @@ public class NewActivity extends WinBoLLActivity implements IWinBoLLActivity {
public void onNew2Activity(View view) {
// WinBoLLActivityManager.getInstance().startWinBoLLActivity(App.getInstance(), New2Activity.class);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.toolbar_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// 在switch语句中处理每个ID并在处理完后返回true未处理的情况返回false。
return super.onOptionsItemSelected(item);
}
}

View File

@@ -1,27 +1,27 @@
package cc.winboll.studio.winboll.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.winboll.R;
import android.app.Activity;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/12/05 18:48
* @Describe Settings Activity
*/
public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivity {
public static final String TAG = "SettingsActivity";
public class SettingsActivity extends BaseWinBoLLActivity {
@Override
public Activity getActivity() {
return this;
}
public static final String TAG = "SettingsActivity";
@Override
public String getTag() {
return TAG;

View File

@@ -1,211 +0,0 @@
package cc.winboll.studio.winboll.activities;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.winboll.R;
import cc.winboll.studio.winboll.WxPayConfig;
import cc.winboll.studio.winboll.utils.SpecUtil;
import cc.winboll.studio.winboll.utils.WxPayApi;
import cc.winboll.studio.winboll.utils.ZXingUtils;
import java.util.Timer;
import java.util.TimerTask;
/**
* 主界面:生成二维码 + 轮询查询支付结果
* @Author ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/07
*/
public class WXPayActivity extends WinBoLLActivity implements IWinBoLLActivity {
private static final String TAG = "WXPayActivity";
// Handler消息标识
private static final int MSG_POLL_TIMEOUT = 1001;
private static final int MSG_POLL_SUCCESS = 1002;
private static final int MSG_POLL_FAILED = 1003;
private ImageView mIvQrCode;
private TextView mTvOrderNo;
private TextView mTvPayStatus;
private Button mBtnCreateOrder;
private String mOutTradeNo; // 商户订单号
private Timer mPollTimer; // 轮询定时器
private long mPollStartTime; // 轮询开始时间
@Override
public Activity getActivity() {
return this;
}
@Override
public String getTag() {
return TAG;
}
private Handler mPollHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case MSG_POLL_TIMEOUT:
stopPoll();
mTvPayStatus.setText("支付状态:轮询超时");
mTvPayStatus.setTextColor(getResources().getColor(android.R.color.darker_gray));
Toast.makeText(WXPayActivity.this, "轮询超时,请手动查询", Toast.LENGTH_SHORT).show();
break;
case MSG_POLL_SUCCESS:
boolean isPaySuccess = (boolean) msg.obj;
String tradeState = (String) msg.getData().getString("tradeState");
stopPoll();
if (isPaySuccess) {
mTvPayStatus.setText("支付状态:支付成功 ✅");
mTvPayStatus.setTextColor(getResources().getColor(android.R.color.holo_green_dark));
Toast.makeText(WXPayActivity.this, "支付成功!", Toast.LENGTH_SHORT).show();
} else {
mTvPayStatus.setText("支付状态:" + tradeState);
mTvPayStatus.setTextColor(getResources().getColor(android.R.color.holo_red_dark));
}
break;
case MSG_POLL_FAILED:
String errorMsg = (String) msg.obj;
mTvPayStatus.setText("查询失败:" + errorMsg);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wxpay);
initView();
initListener();
}
private void initView() {
mIvQrCode = findViewById(R.id.iv_qrcode);
mTvOrderNo = findViewById(R.id.tv_order_no);
mTvPayStatus = findViewById(R.id.tv_pay_status);
mBtnCreateOrder = findViewById(R.id.btn_create_order);
}
private void initListener() {
mBtnCreateOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createOrder();
}
});
}
/**
* 统一下单,生成二维码
*/
private void createOrder() {
mBtnCreateOrder.setEnabled(false);
mTvPayStatus.setText("支付状态:生成订单中...");
mIvQrCode.setImageBitmap(null);
WxPayApi.createOrder(new WxPayApi.OnCreateOrderCallback() {
@Override
public void onSuccess(String outTradeNo, String codeUrl) {
mOutTradeNo = outTradeNo;
mTvOrderNo.setText("商户订单号:" + outTradeNo);
mTvPayStatus.setText("支付状态:未支付,请扫码");
// 生成二维码
Bitmap qrCodeBitmap = ZXingUtils.createQRCodeBitmap(codeUrl, 250, 250);
if (qrCodeBitmap != null) {
mIvQrCode.setImageBitmap(qrCodeBitmap);
// 开始轮询查询支付结果
startPoll();
} else {
mTvPayStatus.setText("支付状态:生成二维码失败");
mBtnCreateOrder.setEnabled(true);
}
}
@Override
public void onFailure(String errorMsg) {
SpecUtil.WWSpecLogError(TAG, "统一下单失败:" + errorMsg);
mTvPayStatus.setText("生成订单失败:" + errorMsg);
mBtnCreateOrder.setEnabled(true);
Toast.makeText(WXPayActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
}
});
}
/**
* 开始轮询查询支付结果
*/
private void startPoll() {
stopPoll(); // 先停止之前的轮询
mPollStartTime = System.currentTimeMillis();
mPollTimer = new Timer();
mPollTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// 检查是否超时
long elapsedTime = System.currentTimeMillis() - mPollStartTime;
if (elapsedTime >= WxPayConfig.POLL_TIMEOUT) {
mPollHandler.sendEmptyMessage(MSG_POLL_TIMEOUT);
return;
}
// 查询订单状态
WxPayApi.queryOrder(mOutTradeNo, new WxPayApi.OnQueryOrderCallback() {
@Override
public void onSuccess(boolean isPaySuccess, String tradeState) {
Message msg = Message.obtain();
msg.what = MSG_POLL_SUCCESS;
msg.obj = isPaySuccess;
Bundle bundle = new Bundle();
bundle.putString("tradeState", tradeState);
msg.setData(bundle);
mPollHandler.sendMessage(msg);
}
@Override
public void onFailure(String errorMsg) {
Message msg = Message.obtain();
msg.what = MSG_POLL_FAILED;
msg.obj = errorMsg;
mPollHandler.sendMessage(msg);
}
});
}
}, 0, WxPayConfig.POLL_INTERVAL);
}
/**
* 停止轮询
*/
private void stopPoll() {
if (mPollTimer != null) {
mPollTimer.cancel();
mPollTimer = null;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
stopPoll();
}
}

View File

@@ -1,47 +0,0 @@
package cc.winboll.studio.winboll.activities;
/**
* @Author ZhanGSKen<zhangsken@qq.com>
* @Date 2025/05/10 09:48
* @Describe WinBoLL 窗口基础类
*/
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libappbase.LogUtils;
public class WinBoLLActivity extends AppCompatActivity {
public static final String TAG = "WinBoLLActivity";
@Override
protected void onResume() {
super.onResume();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
/*if (item.getItemId() == R.id.item_log) {
WinBoLLActivityManager.getInstance().startLogActivity(this);
return true;
} else if (item.getItemId() == R.id.item_home) {
startActivity(new Intent(this, MainActivity.class));
return true;
}*/
// 在switch语句中处理每个ID并在处理完后返回true未处理的情况返回false。
return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
//WinBoLLActivityManager.getInstance().add(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
//WinBoLLActivityManager.getInstance().registeRemove(this);
}
}

View File

@@ -0,0 +1,14 @@
package cc.winboll.studio.winboll.models;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/03/15 08:46
*/
public class NfcTermuxCmd {
public String script; // 要执行的预制脚本名(如 auth.sh
public String[] args; // 脚本参数
public String workDir; // 工作目录
public boolean background; // 是否后台执行
public String resultDir; // 结果输出目录(可为 null
}

View File

@@ -0,0 +1,241 @@
/*
* 源码说明与描述:
* NFC 与 Termux 桥接活动,用于接收外部应用(包调用)传递的 JSON 指令并执行 Termux 脚本命令。
* 支持 ACTION_BUILD后台执行与 ACTION_BUILD_VIEW终端窗口唤起两种动作。
*
* 作者:豆包&ZhanGSKen<zhangsken@qq.com>
* 创建时间2025-03-15 14:00:00
* 最后编辑时间2026-03-16 10:00:00
*/
package cc.winboll.studio.winboll.termux;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.winboll.models.NfcTermuxCmd;
import com.google.gson.Gson;
public class NfcTermuxBridgeActivity extends Activity {
// ========================= 常量与静态属性 =========================
public static final String TAG = "NfcTermuxBridgeActivity";
// 外部应用调用时使用的 Action 常量
public static final String ACTION_BUILD = "cc.winboll.studio.winboll.termux.NfcTermuxBridgeActivity.ACTION_BUILD";
private static final Gson GSON = new Gson();
// ========================= 生命周期方法 =========================
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogUtils.d(TAG, "onCreate() 调用savedInstanceState: " + (savedInstanceState != null ? "非空" : ""));
dispatchIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
LogUtils.d(TAG, "onNewIntent() 调用intent: " + (intent != null ? intent.toString() : "null"));
if (intent != null) {
LogUtils.d(TAG, "onNewIntent() action: " + intent.getAction());
LogUtils.d(TAG, "onNewIntent() data: " + intent.getDataString());
LogUtils.d(TAG, "onNewIntent() extras: " + intent.getExtras());
LogUtils.d(TAG, "onNewIntent() flags: " + intent.getFlags());
LogUtils.d(TAG, "onNewIntent() component: " + intent.getComponent());
} else {
LogUtils.w(TAG, "onNewIntent() intent is null");
}
dispatchIntent(intent);
}
// ========================= 统一 Intent 分发(合并去重) =========================
/**
* 统一分发 Intent根据 Action 路由到不同业务逻辑
* @param intent 外部传入的 Intent
*/
private void dispatchIntent(Intent intent) {
LogUtils.d(TAG, "dispatchIntent() 分发 intent");
if (intent == null) {
LogUtils.w(TAG, "dispatchIntent() intent is null");
return;
}
String action = intent.getAction();
if (ACTION_BUILD.equals(action)) {
ToastUtils.show("ACTION_BUILD 命中");
onOpenTermuxProjectBuild(intent);
} else {
LogUtils.w(TAG, "dispatchIntent() 未知 Action: " + action);
finish();
}
}
// ========================= 核心业务方法 =========================
/**
* 处理 ACTION_BUILD 动作:后台执行 NFC 指令
*/
// private void handleNfcIntent(Intent intent) {
// LogUtils.d(TAG, "handleNfcIntent() 调用");
// if (intent == null) {
// LogUtils.w(TAG, "handleNfcIntent() intent 为空");
// return;
// }
//
// try {
// String json = intent.getStringExtra(Intent.EXTRA_TEXT);
// LogUtils.d(TAG, "handleNfcIntent() json: " + json);
//
// if (json == null || json.isEmpty()) {
// LogUtils.e(TAG, "handleNfcIntent() 指令为空");
// showToast("指令为空");
// finish();
// return;
// }
//
// NfcTermuxCmd cmd = GSON.fromJson(json, NfcTermuxCmd.class);
// LogUtils.d(TAG, "handleNfcIntent() cmd: " + cmd);
//
// if (cmd.script == null || cmd.script.isEmpty()) {
// LogUtils.e(TAG, "handleNfcIntent() script 为空");
// showToast("script 不能为空");
// finish();
// return;
// }
//
// //String scriptPath = "/data/data/com.termux/files/home/TermuxWorkSpaces/BashShells/AutoNFC/" + cmd.script;
// String scriptPath = "/data/data/com.termux/files/home/TermuxWorkSpaces/BashShells/AutoNFC/" + "BuildWinBoLLProject.sh";
// LogUtils.d(TAG, "handleNfcIntent() 脚本路径: " + scriptPath);
//
// boolean success = TermuxCommandExecutor.executeCommand(
// this, scriptPath, cmd.args, cmd.workDir, cmd.background, cmd.resultDir
// );
// LogUtils.d(TAG, "handleNfcIntent() 执行结果: " + success);
//
// if (success) {
// showToast("指令已发送: " + cmd.script);
// LogUtils.i(TAG, "执行成功: " + scriptPath);
// } else {
// showToast("指令发送失败");
// LogUtils.e(TAG, "执行失败");
// }
//
// } catch (Exception e) {
// LogUtils.e(TAG, "handleNfcIntent() 异常: " + e.getMessage(), e);
// showToast("解析失败");
// } finally {
// finish();
// }
// }
/**
* 处理 ACTION_BUILD_VIEW 动作:唤起 Termux 窗口执行命令
*/
public void onOpenTermuxProjectBuild(Intent intent) {
LogUtils.d(TAG, "onOpenTermuxProjectBuildView() 调用");
if (intent == null) {
LogUtils.w(TAG, "onOpenTermuxProjectBuildView() intent 为空");
return;
}
try {
String json = intent.getStringExtra(Intent.EXTRA_TEXT);
LogUtils.d(TAG, "onOpenTermuxProjectBuildView() json: " + json);
if (json == null || json.isEmpty()) {
LogUtils.e(TAG, "onOpenTermuxProjectBuildView() 指令为空");
showToast("指令为空");
finish();
return;
}
NfcTermuxCmd cmd = GSON.fromJson(json, NfcTermuxCmd.class);
LogUtils.d(TAG, "onOpenTermuxProjectBuildView() cmd: " + cmd);
if (cmd.script == null || cmd.script.isEmpty()) {
LogUtils.e(TAG, "onOpenTermuxProjectBuildView() script 为空");
showToast("script 不能为空");
finish();
return;
}
StringBuilder targetCmd = new StringBuilder();
String nfcScriptFolder = "/data/data/com.termux/files/home/TermuxWorkSpaces/BashShells/AutoNFC/";
targetCmd.append("cd " + nfcScriptFolder + " && ");
//targetCmd.append("stdbuf -o0 -e0 -i0 bash ").append(cmd.script).append(" ");
targetCmd.append("stdbuf -o0 -e0 -i0 bash ").append("BuildWinBoLLProject.sh").append(" ");
if (cmd.args != null) {
for (String arg : cmd.args) {
targetCmd.append(arg).append(" ");
}
}
LogUtils.d(TAG, "onOpenTermuxProjectBuildView() 命令: " + targetCmd);
boolean cmdSuccess = TermuxCommandExecutor.executeTerminalCommand(this, targetCmd.toString());
LogUtils.d(TAG, "onOpenTermuxProjectBuildView() 执行结果: " + cmdSuccess);
if (cmdSuccess) {
showToast("指令已发送: " + cmd.script);
} else {
showToast("指令发送失败");
}
} catch (Exception e) {
LogUtils.e(TAG, "onOpenTermuxProjectBuildView() 异常: " + e.getMessage(), e);
showToast("解析失败");
} finally {
finish();
}
}
// ========================= 公共静态测试方法 =========================
/**
* 内部测试方法:发送 ACTION_BUILD 指令
*/
public static void testCommand(Context context) {
LogUtils.d(TAG, "testCommand()");
try {
String testJson = "{\"script\":\"BuildWinBoLLProject.sh\",\"args\":[\"DebugTemp\"],\"workDir\":null,\"background\":true,\"resultDir\":null}";
Intent intent = new Intent(context, NfcTermuxBridgeActivity.class);
intent.setAction(ACTION_BUILD); // 指定 Action
intent.putExtra(Intent.EXTRA_TEXT, testJson);
context.startActivity(intent);
} catch (Exception e) {
LogUtils.e(TAG, "testCommand() 失败: " + e.getMessage());
}
}
/**
* 内部测试方法:发送 ACTION_BUILD_VIEW 指令
*/
// public static void testViewCommand(Context context) {
// LogUtils.d(TAG, "testViewCommand()");
// try {
// String testJson = "{\"script\":\"BuildWinBoLLProjectView.sh\",\"args\":[\"DebugTemp\"],\"workDir\":null,\"background\":true,\"resultDir\":null}";
// Intent intent = new Intent(context, NfcTermuxBridgeActivity.class);
// intent.setAction(ACTION_BUILD_VIEW); // 指定 Action
// intent.putExtra(Intent.EXTRA_TEXT, testJson);
// context.startActivity(intent);
// } catch (Exception e) {
// LogUtils.e(TAG, "testViewCommand() 失败: " + e.getMessage());
// }
// }
// ========================= 工具方法 =========================
/**
* 统一显示 Toast确保在主线程调用
*/
private void showToast(final String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(NfcTermuxBridgeActivity.this, message, Toast.LENGTH_SHORT).show();
}
});
}
}

View File

@@ -0,0 +1,177 @@
package cc.winboll.studio.winboll.termux;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import cc.winboll.studio.libappbase.LogUtils; // 替换 Log 为 LogUtils与 Activity 一致)
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.shell.command.ExecutionCommand.Runner;
/**
* Termux 命令调用工具类(基于 RunCommandService 原型封装)
* 用于向 Termux 发送命令执行请求,兼容 Termux RUN_COMMAND Intent 规范
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/19 16:30:00
* @LastEditTime 2026/01/20 10:15:00
*/
public class TermuxCommandExecutor {
private static final String TAG = "TermuxCommandExecutor";
// 核心修复Termux 官方包名(无 .app 后缀)
private static final String TERMUX_PACKAGE_NAME = "com.termux";
// Termux RunCommandService 完整类名(包名+类名)
private static final String TERMUX_RUN_CMD_SERVICE_CLASS = "com.termux.app.RunCommandService";
private static final String TERMUX_RUN_CMD_ACTION = TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND;
/**
* 执行 Termux 命令(核心方法)
* @param context 上下文(如 Activity、Service
* @param command 要执行的命令路径(如 "/bin/ls"、"/data/data/com.termux/files/usr/bin/bash"
* @param args 命令参数(如 ["-l", "/data/data/com.termux/files/home"]
* @param workDir 工作目录(可为 null默认 Termux 主目录)
* @param isBackground 是否后台执行true=后台false=终端会话执行)
* @param resultDir 命令结果输出目录(可为 null不输出到文件
* @return 是否成功发送命令请求
*/
public static boolean executeCommand(Context context, String command, String[] args, String workDir, boolean isBackground, String resultDir) {
// 1. 校验上下文和命令合法性
if (context == null || command == null || command.isEmpty()) {
LogUtils.e(TAG, "执行命令失败:上下文或命令为空");
return false;
}
// 2. 校验 Termux 是否安装(新增:提前校验,避免白跑流程)
if (!isTermuxInstalled(context)) {
LogUtils.e(TAG, "执行命令失败Termux 未安装");
return false;
}
// 3. 创建 Intent 并设置目标 Service
Intent intent = new Intent(TERMUX_RUN_CMD_ACTION);
intent.setClassName(TERMUX_PACKAGE_NAME, TERMUX_RUN_CMD_SERVICE_CLASS); // 用正确包名
intent.setPackage(TERMUX_PACKAGE_NAME); // 明确包名,避免歧义
// 4. 设置核心命令参数(遵循 Termux RunCommandService 规范)
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_COMMAND_PATH, command);
if (args != null && args.length > 0) {
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_ARGUMENTS, args);
LogUtils.d(TAG, "命令参数:" + String.join(",", args));
}
if (workDir != null && !workDir.isEmpty()) {
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_WORKDIR, workDir);
LogUtils.d(TAG, "工作目录:" + workDir);
}
// 5. 设置执行模式(后台/终端会话)
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_BACKGROUND, isBackground);
String runner = isBackground ? Runner.APP_SHELL.getName() : Runner.TERMINAL_SESSION.getName();
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_RUNNER, runner);
LogUtils.d(TAG, "执行模式:" + (isBackground ? "后台" : "终端会话") + "Runner" + runner);
// 6. 设置命令结果输出(可选,输出到文件)
if (resultDir != null && !resultDir.isEmpty()) {
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_RESULT_DIRECTORY, resultDir);
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_RESULT_SINGLE_FILE, true);
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_RESULT_FILE_BASENAME, "authcenter_cmd_result");
LogUtils.d(TAG, "结果输出目录:" + resultDir);
}
// 7. 允许替换参数中的逗号替代字符
intent.putExtra(TermuxConstants.TERMUX_APP.RUN_COMMAND_SERVICE.EXTRA_REPLACE_COMMA_ALTERNATIVE_CHARS_IN_ARGUMENTS, true);
// 8. 发送请求(区分 Android O 及以上的前台服务)
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
LogUtils.d(TAG, "Android O+ 启动前台服务发送命令");
} else {
context.startService(intent);
LogUtils.d(TAG, "启动普通服务发送命令");
}
LogUtils.i(TAG, "命令发送成功command=" + command);
return true;
} catch (Exception e) {
LogUtils.e(TAG, "命令发送失败:" + e.getMessage(), e);
return false;
}
}
/**
* 简化方法:执行 Termux 终端命令(默认工作目录,终端会话执行)
* @param context 上下文
* @param command 命令(如 "ls -l /home"、"echo 'hello termux'"
* @return 是否成功发送
*/
public static boolean executeTerminalCommand(Context context, String command) {
LogUtils.d(TAG, "调用 executeTerminalCommand命令" + command);
if (command == null || command.isEmpty()) {
LogUtils.e(TAG, "命令为空,执行失败");
return false;
}
// 通过 bash 执行任意终端命令
String[] args = {"-c", command};
return executeCommand(
context,
"/data/data/com.termux/files/usr/bin/bash", // Termux 默认 bash 路径(正确)
args,
"/data/data/com.termux/files/home", // 默认工作目录
false, // 终端会话执行(可见)
null // 不输出到文件
);
}
/**
* 简化方法:后台执行 Termux 命令(无输出文件)
* @param context 上下文
* @param command 命令路径
* @param args 命令参数
* @return 是否成功发送
*/
public static boolean executeBackgroundCommand(Context context, String command, String[] args) {
LogUtils.d(TAG, "调用 executeBackgroundCommandcommand=" + command);
return executeCommand(
context,
command,
args,
null,
true, // 后台执行
null
);
}
/**
* 校验 Termux 是否安装(修复核心错误)
* @param context 上下文
* @return Termux 是否已安装
*/
public static boolean isTermuxInstalled(Context context) {
LogUtils.d(TAG, "校验 Termux 是否安装,包名:" + TERMUX_PACKAGE_NAME);
if (context == null) {
LogUtils.e(TAG, "校验失败:上下文为空");
return false;
}
try {
// 用正确的 Termux 包名查询com.termux
context.getPackageManager().getPackageInfo(TERMUX_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
LogUtils.d(TAG, "Termux 已安装");
return true;
} catch (PackageManager.NameNotFoundException e) {
LogUtils.w(TAG, "Termux 未安装:" + e.getMessage());
return false;
} catch (Exception e) {
LogUtils.e(TAG, "校验 Termux 安装状态异常:" + e.getMessage(), e);
return false;
}
}
/**
* 校验 Termux 是否允许外部应用调用
* @return 校验提示信息
*/
public static String checkTermuxExternalAppPermission() {
String tip = "请确保 Termux 已开启「允许外部应用调用」权限:\n1. 打开 Termux 输入termux-setup-storage\n2. 编辑配置文件echo \"allow-external-apps = true\" > ~/.termux/termux.properties\n3. 重启 Termux 生效";
LogUtils.d(TAG, "外部应用调用权限提示:" + tip);
return tip;
}
}

View File

@@ -0,0 +1,454 @@
package cc.winboll.studio.winboll.unittest;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.winboll.R;
import cc.winboll.studio.winboll.activities.BaseWinBoLLActivity;
import cc.winboll.studio.winboll.termux.NfcTermuxBridgeActivity;
import cc.winboll.studio.winboll.termux.TermuxCommandExecutor;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2026/01/19 11:11:00
* @LastEditTime 2026/01/21 17:45:00
* @Describe Termux环境测试工具跨包+sharedUserId模式
* 适配不同应用包名当前包cc.winboll.studio.winboll.beta / Termux包com.termux
* 支持Termux目录读取、Gradle命令实时输出执行唤起窗口基于sharedUserId实现跨包权限适配
*/
public class TermuxEnvTestActivity extends BaseWinBoLLActivity {
@Override
public Activity getActivity() {
return this;
}
// 常量属性(置顶排列)
public static final String TAG = "TermuxEnvTestActivity";
private static final String TERMUX_HOME_PATH = "/data/data/com.termux/files/home/TermuxWorkSpaces";
private static final String CMD_RESULT_FILE = TERMUX_HOME_PATH + "/CMD_RESULT_FILE.log";
// 成员属性(常量后排列)
private Toolbar mToolbar;
private TextView tvMessage;
private Handler mainHandler;
@Override
public String getTag() {
return TAG;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogUtils.d(TAG, "onCreate() 调用初始化Activity");
setContentView(R.layout.activity_termux_env_test);
initView();
initToolbar();
initTermuxDirectory();
LogUtils.d(TAG, "onCreate() 执行完成");
}
/**
* 初始化视图组件
*/
private void initView() {
LogUtils.d(TAG, "initView() 开始初始化视图");
tvMessage = (TextView) findViewById(R.id.tv_message);
mainHandler = new Handler(Looper.getMainLooper());
// 初始化提示信息
StringBuilder initMsg = new StringBuilder();
initMsg.append("Termux 测试工具(跨包+sharedUserId模式\n");
initMsg.append("-------------------------\n");
initMsg.append("当前应用包名:");
initMsg.append(getPackageName());
initMsg.append("\n");
initMsg.append("Termux应用包名com.termux\n");
initMsg.append("sharedUserIdcom.termux需一致\n");
initMsg.append("支持功能目录读取、Gradle命令实时输出唤起Termux窗口\n");
initMsg.append("-------------------------\n");
tvMessage.setText(initMsg.toString());
LogUtils.d(TAG, "initView() 初始化完成tvMessage初始值" + initMsg.toString().trim());
}
/**
* 初始化Toolbar组件
*/
private void initToolbar() {
LogUtils.d(TAG, "initToolbar() 开始初始化Toolbar");
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (mToolbar == null) {
LogUtils.e(TAG, "initToolbar() 错误未找到Toolbar组件");
return;
}
setSupportActionBar(mToolbar);
mToolbar.setSubtitle(getTag());
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtils.d(TAG, "initToolbar() 导航栏返回按钮点击");
getActivity().finish();
}
});
LogUtils.d(TAG, "initToolbar() 初始化完成");
}
/**
* 初始化Termux目标目录跨包+sharedUserId模式
*/
private void initTermuxDirectory() {
LogUtils.d(TAG, "initTermuxDirectory() 开始初始化Termux目录路径" + TERMUX_HOME_PATH);
File termuxDir = new File(TERMUX_HOME_PATH);
if (termuxDir.exists()) {
LogUtils.d(TAG, "initTermuxDirectory() Termux目录已存在无需创建");
return;
}
tvMessage.append("正在创建Termux目标目录...\n");
boolean createSuccess = termuxDir.mkdirs();
if (createSuccess) {
LogUtils.d(TAG, "initTermuxDirectory() Termux目录创建成功" + TERMUX_HOME_PATH);
tvMessage.append("Termux目录创建成功");
tvMessage.append(TERMUX_HOME_PATH);
tvMessage.append("\n");
} else {
LogUtils.e(TAG, "initTermuxDirectory() 错误Termux目录创建失败");
tvMessage.append("警告Termux目录创建失败\n");
tvMessage.append("请检查:\n");
tvMessage.append("1.AndroidManifest.xml中sharedUserId是否为com.termux\n");
tvMessage.append("2.设备是否已root部分机型需root才能跨包写私有目录\n");
}
}
/**
* 测试读取Termux目录按钮点击事件
*/
public void onTestTermuxEnv(View view) {
LogUtils.d(TAG, "onTestTermuxEnv() 按钮点击开始读取Termux目录");
tvMessage.append("\n【测试读取Termux目录】\n");
String fileListStr = readTermuxHomeFileList();
tvMessage.append(fileListStr);
tvMessage.append("\n-------------------------\n");
LogUtils.d(TAG, "onTestTermuxEnv() 执行完成,读取结果长度:" + fileListStr.length() + "字符");
}
/**
* 测试执行Gradle命令实时输出版唤起Termux窗口
*/
public void onTestTermuxGradleBuildCMD(View view) {
LogUtils.d(TAG, "onTestTermuxCMD() 按钮点击执行Gradle命令实时输出");
tvMessage.append("\n【测试执行Gradle命令实时输出\n");
// 1. 校验Termux是否安装
if (!TermuxCommandExecutor.isTermuxInstalled(this)) {
LogUtils.e(TAG, "onTestTermuxCMD() 错误未安装Termux应用");
tvMessage.append("错误未安装Termux应用包名com.termux\n");
return;
}
// 2. 定义核心路径确保路径与Termux中一致
String gradleFullPath = "/data/data/com.termux/files/home/gradle/gradle-7.5.1/bin/gradle";
String projectPath = TERMUX_HOME_PATH + "/Sources/DebugTemp"; // 项目目录
// 3. 构造命令核心用stdbuf禁用缓冲实现实时输出
String targetCmd = "";
// 步骤1进入项目目录不存在则创建
//targetCmd += "cd " + projectPath + " || (mkdir -p " + projectPath + " && cd " + projectPath + ") && ";
targetCmd += "cd " + projectPath + " && ";
// 步骤2加载环境变量
targetCmd += "source ~/.bashrc && ";
// 步骤3显式配置PATH
targetCmd += "export PATH=/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/home/gradle/gradle-7.5.1/bin:$PATH && ";
// 步骤4用stdbuf禁用stdout/stderr缓冲关键执行Gradle命令
// -o0stdout无缓冲-e0stderr无缓冲-i0stdin无缓冲
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " task --all | grep assemble && ";
targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " -Pandroid.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 assembleBetaDebug && ";
// 步骤5执行成功提示
targetCmd += "echo '\n✅ 命令执行完成!' && echo '\n📌 项目目录:" + projectPath + "' && read -p '按回车键关闭终端...'";
LogUtils.d(TAG, "onTestTermuxCMD() 执行命令:" + targetCmd);
// 4. 执行命令终端会话模式唤起Termux窗口
boolean cmdSuccess = TermuxCommandExecutor.executeTerminalCommand(this, targetCmd);
if (!cmdSuccess) {
LogUtils.e(TAG, "onTestTermuxCMD() 错误:命令发送失败");
tvMessage.append("命令发送失败!\n");
tvMessage.append("可能原因:\n");
tvMessage.append("1.Termux未开启外部应用调用权限执行termux-setup-storage后配置\n");
tvMessage.append("2.sharedUserId配置不一致\n");
tvMessage.append("3.Termux未安装stdbuf执行pkg install coreutils\n");
return;
}
// 5. 应用内提示(说明实时输出特性)
tvMessage.append("已唤起Termux窗口执行说明\n");
tvMessage.append("1. 自动创建/进入项目目录:");
tvMessage.append(projectPath);
tvMessage.append("\n");
tvMessage.append("2. 禁用输出缓冲stdbuf实现Gradle实时输出\n");
tvMessage.append("3. 筛选assemble相关任务grep assemble\n");
tvMessage.append("⚙️ Gradle路径");
tvMessage.append(gradleFullPath);
tvMessage.append("\n");
tvMessage.append("💡 若未实时输出请在Termux中执行pkg install coreutils安装stdbuf\n");
tvMessage.append("-------------------------\n");
}
public void onTestWinBoLLProjectBuild(View view) {
ToastUtils.show("onTestWinBoLLProjectBuild");
NfcTermuxBridgeActivity.testCommand(this);
}
// public void onTestWinBoLLProjectBuildView(View view) {
// ToastUtils.show("onTestWinBoLLProjectBuildView");
// NfcTermuxBridgeActivity.testViewCommand(this);
// }
public void onOpenTermuxBash(View view) {
LogUtils.d(TAG, "onTestTermuxCMD() 按钮点击执行Gradle命令实时输出");
tvMessage.append("\n【测试执行Gradle命令实时输出\n");
// 1. 校验Termux是否安装
if (!TermuxCommandExecutor.isTermuxInstalled(this)) {
LogUtils.e(TAG, "onTestTermuxCMD() 错误未安装Termux应用");
tvMessage.append("错误未安装Termux应用包名com.termux\n");
return;
}
// 2. 定义核心路径确保路径与Termux中一致
String gradleFullPath = "/data/data/com.termux/files/home/gradle/gradle-7.5.1/bin/gradle";
String projectPath = TERMUX_HOME_PATH + "/"; // 项目目录
// 3. 构造命令核心用stdbuf禁用缓冲实现实时输出
String targetCmd = "";
// 步骤1进入项目目录不存在则创建
targetCmd += "cd " + projectPath + " && ";
// 步骤2加载环境变量
targetCmd += "source ~/.bashrc && ";
// 步骤3显式配置PATH
targetCmd += "export PATH=/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/home/gradle/gradle-7.5.1/bin:$PATH && ";
// 步骤4用stdbuf禁用stdout/stderr缓冲关键执行Gradle命令
// -o0stdout无缓冲-e0stderr无缓冲-i0stdin无缓冲
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " task --all | grep assemble && ";
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " -Pandroid.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 assembleBetaDebug && ";
targetCmd += "stdbuf -o0 -e0 -i0 bash && ";
// 步骤5执行成功提示
targetCmd += "echo '\n✅ 命令执行完成!' && echo '\n📌 项目目录:" + projectPath + "' && read -p '按回车键关闭终端...'";
LogUtils.d(TAG, "onTestTermuxCMD() 执行命令:" + targetCmd);
// 4. 执行命令终端会话模式唤起Termux窗口
boolean cmdSuccess = TermuxCommandExecutor.executeTerminalCommand(this, targetCmd);
if (!cmdSuccess) {
LogUtils.e(TAG, "onTestTermuxCMD() 错误:命令发送失败");
tvMessage.append("命令发送失败!\n");
tvMessage.append("可能原因:\n");
tvMessage.append("1.Termux未开启外部应用调用权限执行termux-setup-storage后配置\n");
tvMessage.append("2.sharedUserId配置不一致\n");
tvMessage.append("3.Termux未安装stdbuf执行pkg install coreutils\n");
return;
}
// 5. 应用内提示(说明实时输出特性)
tvMessage.append("已唤起Termux窗口执行说明\n");
tvMessage.append("1. 自动创建/进入项目目录:");
tvMessage.append(projectPath);
tvMessage.append("\n");
tvMessage.append("2. 禁用输出缓冲stdbuf实现Gradle实时输出\n");
tvMessage.append("3. 筛选assemble相关任务grep assemble\n");
tvMessage.append("⚙️ Gradle路径");
tvMessage.append(gradleFullPath);
tvMessage.append("\n");
tvMessage.append("💡 若未实时输出请在Termux中执行pkg install coreutils安装stdbuf\n");
tvMessage.append("-------------------------\n");
}
/**
* 跨包读取Termux命令结果文件保留原功能兼容其他场景
*/
private String readCmdResultDirectly() {
LogUtils.d(TAG, "readCmdResultDirectly() 开始读取命令结果,文件路径:" + CMD_RESULT_FILE);
File resultFile = new File(CMD_RESULT_FILE);
// 校验文件存在性
if (!resultFile.exists()) {
LogUtils.e(TAG, "readCmdResultDirectly() 错误:结果文件不存在");
return "错误:结果文件不存在\n可能原因\n1.命令执行失败\n2.延迟时间不足\n3.跨包写权限被拒绝需root";
}
// 校验文件可读性
if (!resultFile.canRead()) {
LogUtils.e(TAG, "readCmdResultDirectly() 错误:无结果文件读取权限");
return "错误无结果文件读取权限sharedUserId配置错误或未root";
}
// 读取文件内容
StringBuilder result = new StringBuilder();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(resultFile), StandardCharsets.UTF_8));
String line;
while ((line = br.readLine()) != null) {
result.append(line);
result.append("\n");
}
LogUtils.d(TAG, "readCmdResultDirectly() 文件读取完成,结果长度:" + result.length() + "字符");
} catch (IOException e) {
LogUtils.e(TAG, "readCmdResultDirectly() 错误:文件读取异常", e);
return "错误:读取文件异常 → " + e.getMessage();
} finally {
if (br != null) {
try {
br.close();
LogUtils.d(TAG, "readCmdResultDirectly() BufferedReader资源已关闭");
} catch (IOException e) {
LogUtils.e(TAG, "readCmdResultDirectly() 错误BufferedReader关闭异常", e);
}
}
}
String resultStr = result.toString().trim();
return resultStr.isEmpty() ? "命令执行成功,但无输出" : resultStr;
}
/**
* 删除命令结果临时文件(保留原功能)
*/
private void deleteCmdResultFile() {
LogUtils.d(TAG, "deleteCmdResultFile() 开始删除临时文件,路径:" + CMD_RESULT_FILE);
File resultFile = new File(CMD_RESULT_FILE);
if (!resultFile.exists()) {
LogUtils.d(TAG, "deleteCmdResultFile() 临时文件不存在,无需删除");
return;
}
if (resultFile.canWrite()) {
boolean deleteSuccess = resultFile.delete();
if (deleteSuccess) {
LogUtils.d(TAG, "deleteCmdResultFile() 临时文件删除成功");
} else {
LogUtils.w(TAG, "deleteCmdResultFile() 警告:临时文件删除失败");
tvMessage.append("警告:临时结果文件删除失败\n");
}
} else {
LogUtils.w(TAG, "deleteCmdResultFile() 警告:无临时文件删除权限");
}
}
/**
* 跨包读取Termux目录文件列表保留原功能
*/
private String readTermuxHomeFileList() {
LogUtils.d(TAG, "readTermuxHomeFileList() 开始读取目录,路径:" + TERMUX_HOME_PATH);
File termuxHomeDir = new File(TERMUX_HOME_PATH);
StringBuilder result = new StringBuilder();
// 基础校验
if (!termuxHomeDir.exists()) {
LogUtils.e(TAG, "readTermuxHomeFileList() 错误:目录不存在");
return "错误Termux目录不存在 → " + TERMUX_HOME_PATH;
}
if (!termuxHomeDir.isDirectory()) {
LogUtils.e(TAG, "readTermuxHomeFileList() 错误:指定路径不是目录");
return "错误:指定路径不是目录 → " + TERMUX_HOME_PATH;
}
if (!termuxHomeDir.canRead()) {
LogUtils.e(TAG, "readTermuxHomeFileList() 错误:无目录读取权限");
return "错误无目录读取权限需满足1.sharedUserId=com.termux 2.设备root";
}
// 获取文件列表
File[] files = termuxHomeDir.listFiles();
if (files == null || files.length == 0) {
LogUtils.d(TAG, "readTermuxHomeFileList() 目录为空");
return "Termux目录为空 → " + TERMUX_HOME_PATH;
}
// 拼接结果字符串
result.append("Termux主目录");
result.append(TERMUX_HOME_PATH);
result.append("\n");
result.append("文件/子目录总数:");
result.append(files.length);
result.append("\n");
result.append("目录权限:");
result.append("读:");
result.append(termuxHomeDir.canRead());
result.append(" | 写:");
result.append(termuxHomeDir.canWrite());
result.append("\n");
result.append("-------------------------\n");
for (File file : files) {
String fileType = file.isDirectory() ? "[目录]" : "[文件]";
String fileName = file.getName();
String filePath = file.getAbsolutePath();
String fileSize = file.isFile() ? " | 大小:" + formatFileSize(file.length()) : "";
String filePerm = " | 权限r:" + file.canRead() + "/w:" + file.canWrite();
result.append(fileType);
result.append(" ");
result.append(fileName);
result.append(fileSize);
result.append(filePerm);
result.append("");
result.append(filePath);
result.append("\n");
}
LogUtils.d(TAG, "readTermuxHomeFileList() 读取完成,结果长度:" + result.length() + "字符");
return result.toString().trim();
}
/**
* 格式化文件大小B→KB→MB
*/
private String formatFileSize(long length) {
LogUtils.d(TAG, "formatFileSize() 调用,文件长度:" + length + "B");
String sizeStr;
if (length < 1024) {
sizeStr = length + "B";
} else if (length < 1024 * 1024) {
sizeStr = String.format("%.1fKB", length / 1024.0);
} else {
sizeStr = String.format("%.1fMB", length / (1024.0 * 1024));
}
LogUtils.d(TAG, "formatFileSize() 格式化结果:" + sizeStr);
return sizeStr;
}
@Override
protected void onDestroy() {
super.onDestroy();
LogUtils.d(TAG, "onDestroy() 调用,清理资源");
deleteCmdResultFile();
if (mainHandler != null) {
mainHandler.removeCallbacksAndMessages(null);
LogUtils.d(TAG, "onDestroy() Handler资源已释放");
}
LogUtils.d(TAG, "onDestroy() 执行完成");
}
}

View File

@@ -7,10 +7,10 @@ import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.winboll.R;
import cc.winboll.studio.winboll.activities.WinBoLLActivity;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
@@ -18,7 +18,7 @@ import cc.winboll.studio.winboll.activities.WinBoLLActivity;
* @Describe 企业微信SDK接口测试基础调试版
* 包含SDK初始化、基础接口调用、日志输出、主线程回调处理
*/
public class TestWeWorkSpecSDK extends WinBoLLActivity implements IWinBoLLActivity, View.OnClickListener {
public class TestWeWorkSpecSDK extends AppCompatActivity implements IWinBoLLActivity, View.OnClickListener {
public static final String TAG = "TestWeWorkSpecSDK";

View File

@@ -1,210 +0,0 @@
package com.tencent.wework;
import java.util.Map;
import java.util.HashMap;;
/**
* @warning: 1. 不要修改成员变量名native方法内有反射调用
* 2. 调用本地方法需保持包结构本工具需放在包com.tencent.wework内
* 3. 不允许继承类名和函数名均不可修改会影响本地方法的引用详见javah生成本地方法头文件
*/
public final class SpecCallbackSDK {
/**
* @description 调用本地方法后实例化的对象指针
*/
private long specCallbackSDKptr = 0;
public long GetPtr() { return specCallbackSDKptr; }
/**
* @description: 回包的headers
*/
private Map<String, String> responseHeaders;
public Map<String, String> GetResponseHeaders() { return responseHeaders; }
/**
* @description: 回包的加密后的body
*/
private String responseBody;
public String GetResponseBody() { return responseBody; }
/**
* @description: 每个请求构造一个SpecCallbackSDK示例,
* SpecCallbackSDK仅持有headers和body的引用,
* 因此需保证headers和body的生存期比SpecCallbackSDK长
* @param method: 请求方法GET/POST
* @param headers: 请求header
* @param body: 请求body
* @example:
* SpecCallbackSDK sdk = new SpecCallbackSDK(method, headers, body);
* if (sdk.IsOk()) {
* String corpid = sdk.GetCorpId();
* String agentid = sdk.GetAgentId();
* String call_type = sdk.GetCallType();
* String data = sdk.GetData();
* //do something...
* }
* String response = ...;
* sdk.BuildResponseHeaderBody(response);
* Map<String, String> responseHeaders = sdk.GetResponseHeaders();
* String body = sdk.GetResponseBody();
* //do response
*
* @return errorcode 示例如下:
* -920001: 未设置请求方法
* -920002: 未设置请求header
* -920003: 未设置请求body
* */
public SpecCallbackSDK(String method, Map<String, String> headers, String body) {
try {
specCallbackSDKptr = NewCallbackSDK(method, headers, body);
} catch (Exception e) {
SpecUtil.WWSpecLogError("SpecCallbackSDK exception caught", e.getMessage());
}
}
private native long NewCallbackSDK(String method, Map<String, String> headers, String body);
/**
* @usage 在Java对象的内存回收前析构C++对象
*/
@Override
protected void finalize() throws Throwable {
DeleteCPPInstance(specCallbackSDKptr);
super.finalize();
}
private native void DeleteCPPInstance(long specCallbackSDKptr);
/**
* @description: 判断构造函数中传入的请求是否解析成功
* @return: 成功与否
* */
public boolean IsOk() {
return IsOk(specCallbackSDKptr);
}
private native boolean IsOk(long specCallbackSDKptr);
/**
* @description: 获取请求的企业
* @require: 仅当IsOk() == true可调用
* @return: corpid
* */
public String GetCorpId() {
return GetCorpId(specCallbackSDKptr);
}
private native String GetCorpId(long specCallbackSDKptr);
/**
* @description: 获取请求的应用
* @require: 仅当IsOk() == true可调用
* @return: agentid
* */
public long GetAgentId() {
return GetAgentId(specCallbackSDKptr);
}
private native long GetAgentId(long specCallbackSDKptr);
/**
* @description: 获取请求的类型
* @require: 仅当IsOk() == true可调用
* @return: 1 - 来自[应用调用专区]的请求
* 2 - 来自企业微信的回调事件
* */
public long GetCallType() {
return GetCallType(specCallbackSDKptr);
}
private native long GetCallType(long specCallbackSDKptr);
/**
* @description: 获取请求数据
* @require: 仅当IsOk() == true可调用
* @return: 请求数据,根据call_type可能是:
* - 企业微信回调事件
* - [应用调用专区]接口中的request_data
* */
public String GetData() {
return GetData(specCallbackSDKptr);
}
private native String GetData(long specCallbackSDKptr);
/**
* @description: 是否异步请求
* @require: 仅当IsOk() == true可调用
* @return: 是否异步请求
* */
public boolean GetIsAsync() {
return GetIsAsync(specCallbackSDKptr);
}
private native boolean GetIsAsync(long specCallbackSDKptr);
/**
* @description: 获取请求的job_info,
* @require: 仅当IsOk() == true可调用
* @return: job_info,无需理解内容,
* 在同一个请求上下文中使用SpecSDK的时候传入
* */
public String GetJobInfo() {
return GetJobInfo(specCallbackSDKptr);
}
private native String GetJobInfo(long specCallbackSDKptr);
/**
* @description: 获取请求的ability_id,[应用调用专区]接口时指定
* @require: 仅当IsOk() == true可调用
* @return: ability_id
* */
public String GetAbilityId() {
return GetAbilityId(specCallbackSDKptr);
}
private native String GetAbilityId(long specCallbackSDKptr);
/**
* @description: 获取请求的notify_id,用于[应用同步调用专区程序]接口
* @require: 仅当IsOk() == true可调用
* @return: notify_id
* */
public String GetNotifyId() {
return GetNotifyId(specCallbackSDKptr);
}
private native String GetNotifyId(long specCallbackSDKptr);
/**
* @description: 对返回包计算签名&加密
* @param response: 待加密的回包明文.如果IsOk()==false,传入空串即可
* @note 本接口的执行问题可查看日志
* */
public void BuildResponseHeaderBody(String response) {
try {
responseHeaders = new HashMap<String, String>();
responseBody = "";
BuildResponseHeaderBody(specCallbackSDKptr, response);
} catch (Exception e) {
SpecUtil.WWSpecLogError("SpecCallbackSDK exception caught", e.getMessage());
}
}
private native void BuildResponseHeaderBody(long specCallbackSDKptr, String response);
// 静态代码块内还无法调用native日志函数这里的日志在管理系统无法查询
static {
try {
Class.forName("com.tencent.wework.SpecUtil");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
}
}

View File

@@ -1,163 +0,0 @@
package com.tencent.wework;
/**
* @warning: 1. 不要修改成员变量名native方法内有反射调用
* 2. 调用本地方法需保持包结构本工具需放在包com.tencent.wework内
* 3. 不允许继承类名和函数名均不可修改会影响本地方法的引用详见javah生成本地方法头文件
*/
public final class SpecSDK {
/**
* @description 调用本地方法后实例化的对象指针
*/
private long specSDKptr = 0;
/**
* @usage invoke的请求
* @example "{\"limit\":1}
*/
private String request;
public void SetRequest(String request) {
this.request = request;
}
/**
* @usage 访问上一次invoke的结果
*/
private String response;
public String GetResponse() {
return response;
}
/**
* @param corpid: 企业corpid必选参数
* @param agentid: 应用id必选参数
* @param ability_id: 能力ID可选参数
* @param job_info: job_info可选参数
* */
public SpecSDK(String corpId, long agentId) {
specSDKptr = NewSDK1(corpId, agentId);
}
private native long NewSDK1(String corpId, long agentId);
public SpecSDK(String corpId, long agentId, String abilityId) {
specSDKptr = NewSDK2(corpId, agentId, abilityId);
}
private native long NewSDK2(String corpId, long agentId, String abilityId);
public SpecSDK(String corpId, long agentId, String abilityId, String jobInfo) {
specSDKptr = NewSDK3(corpId, agentId, abilityId, jobInfo);
}
private native long NewSDK3(String corpId, long agentId, String abilityId, String jobInfo);
/**
* @description 使用callback的请求来初始化
* @param callback_sdk: 要求IsOk()==true
* @return C++内部指针创建失败时指针仍为0并输出错误日志
* */
public SpecSDK(SpecCallbackSDK callbackSDK) {
specSDKptr = NewSDK4(callbackSDK.GetPtr());
}
private native long NewSDK4(long callbackSDK);
/**
* @usage 在Java对象的内存回收前析构C++对象
*/
@Override
protected void finalize() throws Throwable {
DeleteCPPInstance(specSDKptr);
super.finalize();
}
private native void DeleteCPPInstance(long specSDKptr);
/**
* @description 用于在专区内调用企业微信接口
* @param api_name 接口名
* @param request json格式的请求数据
* @param response json格式的返回数据
* @return errorcode 参考如下:
* 0: 成功
* -910001: SDK没有初始化
* -910002: 没有设置请求体
* -910003: 没有设置请求的API
* -910004: 在SDK成员内找不到成员"response",注意lib内有反射机制,不要修改成员变量名
* -910005: 使用未初始化的callback初始化SDK
* -910006: invoke调用失败,应检查日志查看具体原因
* -910007: 响应体为空
* @note 当返回0时,表示没有网络或请求协议层面或调用方法的失败,
* 调用方需继续检查response中的errcode字段确保业务层面的成功
*
* @usage 当前版本sdk支持的接口列表,每个接口的具体协议请查看企业微信文档:
* https://developer.work.weixin.qq.com/document/path/91201
*
* +--------------------------------+--------------------------------+
* |接口名 |描述 |
* |--------------------------------|--------------------------------|
* |program_async_job_call_back |上报异步任务结果 |
* |sync_msg |获取会话记录 |
* |get_group_chat |获取内部群信息 |
* |get_agree_status_single |获取单聊会话同意情况 |
* |get_agree_status_room |获取群聊会话同意情况 |
* |set_hide_sensitiveinfo_config |设置成员会话组件敏感信息隐藏配置|
* |get_hide_sensitiveinfo_config |获取成员会话组件敏感信息隐藏配置|
* |search_chat |会话名称搜索 |
* |search_msg |会话消息搜索 |
* |create_rule |新增关键词规则 |
* |get_rule_list |获取关键词列表 |
* |get_rule_detail |获取关键词规则详情 |
* |update_rule |修改关键词规则 |
* |delete_rule |删除关键词规则 |
* |get_hit_msg_list |获取命中关键词规则的会话记录 |
* |create_sentiment_task |创建情感分析任务 |
* |get_sentiment_result |获取情感分析结果 |
* |create_summary_task |创建摘要提取任务 |
* |get_summary_result |获取摘要提取结果 |
* |create_customer_tag_task |创建标签匹配任务 |
* |get_customer_tag_result |获取标签任务结果 |
* |create_recommend_dialog_task |创建话术推荐任务 |
* |get_recommend_dialog_result |获取话术推荐结果 |
* |create_private_task |创建自定义模型任务 |
* |get_private_task_result |获取自定义模型结果 |
* |(废弃)document_list |获取知识集列表 |
* |create_spam_task |会话反垃圾创建分析任务 |
* |get_spam_result |会话反垃圾获取任务结果 |
* |create_chatdata_export_job |创建会话内容导出任务 |
* |get_chatdata_export_job_status |获取会话内容导出任务结果 |
* |spec_notify_app |专区通知应用 |
* |create_program_task |创建自定义程序任务 |
* |get_program_task_result |获取自定义程序结果 |
* |knowledge_base_list |获取企业授权给应用的知识集列表 |
* |knowledge_base_create |创建知识集 |
* |knowledge_base_detail |获取知识集详情 |
* |knowledge_base_add_doc |添加知识集內容 |
* |knowledge_base_remove_doc |删除知识集內容 |
* |knowledge_base_modify_name |修改知识集名称 |
* |knowledge_base_delete |删除知识集 |
* |search_contact_or_customer |员工或者客户名称搜索 |
* |create_ww_model_task |创建企微通用模型任务 |
* |get_ww_model_result |获取企微通用模型结果 |
* |get_msg_list_by_page_id |page_id获取消息列表 |
* +-----------------------------------------------------------------+
* */
public int Invoke(String apiName) {
return Invoke(specSDKptr, apiName, request);
}
private native int Invoke(long sdk, String apiName, String request);
// 静态代码块内还无法调用native日志函数这里的日志在管理系统无法查询
static {
try {
Class.forName("com.tencent.wework.SpecUtil");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,171 +0,0 @@
package com.tencent.wework;
//import java.lang.management.ManagementFactory;
//import java.lang.management.RuntimeMXBean;
/**
* @warning: 1. 不要修改成员变量名native方法内有反射调用
* 2. 调用本地方法需保持包结构本工具需放在包com.tencent.wework内
* 3. 不允许继承类名和函数名均不可修改会影响本地方法的引用详见javah生成本地方法头文件
* 4. 使用其他工具打印的日志将无法被查询如需使用SLF4j风格的日志或性能更好的日志框架
* 请自行封装SpecUtil.SpecLog或SpecUtil.SpecLogNative方法
*
* @usage: 1. 获取SDK的版本号
* 2. 打印三个级别的日志
* 3. 开启调试模式
*/
public final class SpecUtil {
/**
* @description SDK版本号
* @usage 可用于校对不同SDK版本或后续针对不同的SDK版本添加业务逻辑
*/
private static final String SDK_VERSION = "1.4.0";
public static String GetSDKVersion() {
return SDK_VERSION;
}
/**
* @description 正确的包名SDK必须存放在"com.tencent.wework"下,否则会影响本地方法的调用
*/
private static final String EXPECTED_PACKAGE_NAME = "com.tencent.wework";
public static String GetExpectedPackageName() {
return EXPECTED_PACKAGE_NAME;
}
private static final String LINE_SEPERATOR = System.getProperty("line.separator");
public static void WWSpecLogInfo(String... args) {
SpecLog('I', args);
}
public static void WWSpecLogError(String... args) {
SpecLog('E', args);
}
public static void WWSpecLogDebug(String... args) {
SpecLog('D', args);
}
public static void WWSpecLogInfoWithReqId(String reqId, String... args) {
SpecLogWithReqId(reqId, 'I', args);
}
public static void WWSpecLogErrorWithReqId(String reqId, String... args) {
SpecLogWithReqId(reqId, 'E', args);
}
public static void WWSpecLogDebugWithReqId(String reqId, String... args) {
SpecLogWithReqId(reqId, 'D', args);
}
/**
* @usage 打印标准日志
* @note 只有使用SpecLog和SpecLogNative函数打印的日志能被调试平台查询其他框架的日志仅能本地查看
* @param logLevel 日志级别使用char传递目前支持I——INFO、E——ERROR、D——DEBUG
* @param args 自定义参数
*/
public static void SpecLog(char logLevel, String... args) {
StackTraceElement element = Thread.currentThread().getStackTrace()[3];
SpecLogNative(
logLevel,
element.getFileName(),
element.getLineNumber(),
String.join(",", args).replace(LINE_SEPERATOR, " ")
);
}
/**
* @usage 打印标准日志
* @note 只有使用SpecLog和SpecLogNative函数打印的日志能被调试平台查询其他框架的日志仅能本地查看
* @param reqid 请求id
* @param logLevel 日志级别使用char传递目前支持I——INFO、E——ERROR、D——DEBUG
* @param args 自定义参数
*/
public static void SpecLogWithReqId(String reqId, char logLevel, String... args) {
StackTraceElement element = Thread.currentThread().getStackTrace()[3];
SpecLogNativeWithReqId(
reqId,
logLevel,
element.getFileName(),
element.getLineNumber(),
String.join(",", args).replace(LINE_SEPERATOR, " ")
);
}
/**
* @usage 打印标准日志
* @note 只有使用SpecLog和SpecLogNative函数打印的日志能被调试平台查询其他框架的日志仅能本地查看
* 如需SLF4J风格的接口或对日志性能有进一步需求开发者可以自行封装该函数
* @param logLevel 日志级别使用char传递目前支持I——INFO、E——ERROR、D——DEBUG
* @param fileName 文件名(类名)
* @param lineNumber 行号
* @param argsString 自定义参数
*/
public static native void SpecLogNative(char logLevel, String fileName, int lineNumber, String argsString);
/**
* @usage 打印标准日志
* @note 只有使用SpecLog和SpecLogNative函数打印的日志能被调试平台查询其他框架的日志仅能本地查看
* 如需SLF4J风格的接口或对日志性能有进一步需求开发者可以自行封装该函数
* @param reqid 请求id
* @param logLevel 日志级别使用char传递目前支持I——INFO、E——ERROR、D——DEBUG
* @param fileName 文件名(类名)
* @param lineNumber 行号
* @param argsString 自定义参数
*/
public static native void SpecLogNativeWithReqId(String reqId, char logLevel, String fileName, int lineNumber, String argsString);
/**
* @usage 开启调试模式,进程级别开关
* @param debugToken 调试凭证,在管理端获取
* @param accessToken 应用access token
* @return 是否开启成功
*/
public static boolean SpecOpenDebugMode(String debugToken, String accessToken) {
return SpecOpenDebugModeNative(debugToken, accessToken);
}
private static native boolean SpecOpenDebugModeNative(String debugToken, String accessToken);
/**
* @usage 生成notify id。用户可调用本接口生成notify id也可完全自定义生成
* @return 新的notify id支持纳秒级隔离内部异常时会输出日志并返回空串
* @note 1. 用户可先生成notify id将其与回调数据关联存储后再使用该notify id通知应用
* 从而保证回调数据被请求时已存储完毕
*/
public static String GenerateNotifyId() {
return GenerateNotifyIdNative();
}
private static native String GenerateNotifyIdNative();
static {
// 检查包名
String packageName = SpecUtil.class.getPackage().getName();
if (!EXPECTED_PACKAGE_NAME.equals(packageName)) {
// 静态代码块内还无法调用native日志函数这里的日志在管理系统无法查询
System.out.println("SpecUtil class must be in package com.tencent.wework");
System.exit(1);
}
// 加载so库
try {
System.loadLibrary("WeWorkSpecSDK");
} catch (UnsatisfiedLinkError e) {
System.out.println("libWeWorkSpecSDK.so not found in java.library.path");
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
System.out.println("unexpected exception: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
SpecUtil.WWSpecLogInfo("SDK init done", "packageName=" + packageName, "SDK_VERSION=" + SDK_VERSION);
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"/>
<cc.winboll.studio.libappbase.views.AboutView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:id="@+id/aboutview"/>
</LinearLayout>

View File

@@ -6,14 +6,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
<cc.winboll.studio.winboll.CustomToolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:toolbarTitle="@string/app_name"
app:toolbarTitleColor="@color/colorAccent"
app:toolbarBackgroundColor="@color/colorPrimary"
android:id="@+id/toolbar"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"

View File

@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"/>

View File

@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"/>

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Termux Bash"
android:onClick="onOpenTermuxBash"/>
<Button
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Termux Gradle Build CMD"
android:onClick="onTestTermuxGradleBuildCMD"/>
<Button
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Termux Env"
android:onClick="onTestTermuxEnv"/>
<Button
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test WinBoLL Project Build"
android:onClick="onTestWinBoLLProjectBuild"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"
android:id="@+id/tv_message"
android:textIsSelectable="true"/>
</ScrollView>
</LinearLayout>

View File

@@ -8,6 +8,6 @@
android:id="@+id/item_settings"
android:title="Settings"/>
<item
android:id="@+id/item_wxpayactivity"
android:title="WXPayActivity"/>
android:id="@+id/item_about"
android:title="About"/>
</menu>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="UnitTest">
<menu >
<item
android:id="@+id/item_termux_env_test"
android:title="TermuxEnvTestActivity"/>
</menu>
</item>
</menu>

View File

@@ -1,5 +1,6 @@
<resources>
<string name="app_name">WinBoLL</string>
<string name="app_description">WinBoLL 网站浏览器。</string>
<string name="app_name_cn1">筋斗云</string>
<string name="app_name_cn2">金抖云</string>
<string name="switchto_en1">WinBoLL</string>

View File

@@ -11,5 +11,11 @@
<certificates src="system" />
</trust-anchors>
</base-config>
<!-- 允许特定域名的明文请求仅本地127.0.0.1 -->
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>