mirror of
https://gitea.winboll.cc/Studio/OriginMaster.git
synced 2026-02-04 13:32:20 +08:00
添加Termux环境测试
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon Jan 19 03:20:58 GMT 2026
|
||||
#Mon Jan 19 03:33:40 GMT 2026
|
||||
stageCount=11
|
||||
libraryProject=
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.10
|
||||
buildCount=5
|
||||
buildCount=6
|
||||
baseBetaVersion=15.11.11
|
||||
|
||||
@@ -9,17 +9,23 @@ import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.winboll.MainActivity;
|
||||
import cc.winboll.studio.winboll.R;
|
||||
import cc.winboll.studio.winboll.activities.BaseWinBoLLActivity;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/19 11:11
|
||||
* @Describe Termux 环境测试
|
||||
* @LastEditTime 2026/01/19 15:30
|
||||
* @Describe Termux 环境测试(新增:读取Termux主目录文件列表功能)
|
||||
*/
|
||||
public class TermuxEnvTestActivity extends BaseWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "TermuxEnvTestActivity";
|
||||
// Termux主目录固定路径
|
||||
private static final String TERMUX_HOME_PATH = "/data/data/com.termux/files/home";
|
||||
|
||||
private Toolbar mToolbar;
|
||||
private Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
@@ -33,7 +39,7 @@ public class TermuxEnvTestActivity extends BaseWinBoLLActivity {
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
private void initToolbar() {
|
||||
private void initToolbar() {
|
||||
LogUtils.d(TAG, "initToolbar() 开始初始化");
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (mToolbar == null) {
|
||||
@@ -42,7 +48,7 @@ public class TermuxEnvTestActivity extends BaseWinBoLLActivity {
|
||||
}
|
||||
setSupportActionBar(mToolbar);
|
||||
mToolbar.setSubtitle(getTag());
|
||||
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -53,4 +59,67 @@ public class TermuxEnvTestActivity extends BaseWinBoLLActivity {
|
||||
});
|
||||
LogUtils.d(TAG, "initToolbar() 配置完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心功能:读取Termux主目录文件列表,返回字符串格式
|
||||
* @return 目录路径+文件列表(换行分隔),异常时返回错误信息
|
||||
*/
|
||||
public String readTermuxHomeFileList() {
|
||||
LogUtils.d(TAG, "开始读取Termux目录:" + TERMUX_HOME_PATH);
|
||||
File termuxHomeDir = new File(TERMUX_HOME_PATH);
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
// 1. 检查目录是否存在
|
||||
if (!termuxHomeDir.exists()) {
|
||||
String errorMsg = "错误:Termux目录不存在 → " + TERMUX_HOME_PATH;
|
||||
LogUtils.e(TAG, errorMsg);
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
// 2. 检查是否为目录
|
||||
if (!termuxHomeDir.isDirectory()) {
|
||||
String errorMsg = "错误:指定路径不是目录 → " + TERMUX_HOME_PATH;
|
||||
LogUtils.e(TAG, errorMsg);
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
// 3. 检查读写权限
|
||||
if (!termuxHomeDir.canRead()) {
|
||||
String errorMsg = "错误:无目录读取权限 → " + TERMUX_HOME_PATH;
|
||||
LogUtils.e(TAG, errorMsg);
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
// 4. 获取目录下所有文件/子目录
|
||||
File[] files = termuxHomeDir.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
String emptyMsg = "Termux目录为空 → " + TERMUX_HOME_PATH;
|
||||
LogUtils.d(TAG, emptyMsg);
|
||||
return emptyMsg;
|
||||
}
|
||||
|
||||
// 5. 拼接文件列表字符串(包含类型、名称、路径)
|
||||
result.append("Termux主目录:").append(TERMUX_HOME_PATH).append("\n");
|
||||
result.append("文件/子目录总数:").append(files.length).append("\n");
|
||||
result.append("-------------------------\n");
|
||||
for (File file : files) {
|
||||
String fileType = file.isDirectory() ? "[目录]" : "[文件]";
|
||||
String fileName = file.getName();
|
||||
String filePath = file.getAbsolutePath();
|
||||
result.append(fileType).append(" ").append(fileName).append(" → ").append(filePath).append("\n");
|
||||
}
|
||||
|
||||
// 6. 去除末尾多余换行
|
||||
String fileListStr = result.toString().trim();
|
||||
LogUtils.d(TAG, "Termux目录读取完成,结果长度:" + fileListStr.length());
|
||||
return fileListStr;
|
||||
}
|
||||
|
||||
public void onTestTermuxEnv(View view) {
|
||||
TextView tvMessage = findViewById(R.id.tv_message);
|
||||
// 测试:读取Termux目录文件列表并打印日志
|
||||
String fileListStr = readTermuxHomeFileList();
|
||||
tvMessage.append(fileListStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
<?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">
|
||||
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="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TestTermuxEnv"
|
||||
android:onClick="onTestTermuxEnv"/>
|
||||
|
||||
</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"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user