|
|
|
|
@@ -26,7 +26,6 @@ public class NfcTermuxBridgeActivity extends Activity {
|
|
|
|
|
|
|
|
|
|
// 外部应用调用时使用的 Action 常量
|
|
|
|
|
public static final String ACTION_BUILD = "cc.winboll.studio.winboll.termux.NfcTermuxBridgeActivity.ACTION_BUILD";
|
|
|
|
|
public static final String ACTION_BUILD_VIEW = "cc.winboll.studio.winboll.termux.NfcTermuxBridgeActivity.ACTION_BUILD_VIEW";
|
|
|
|
|
|
|
|
|
|
private static final Gson GSON = new Gson();
|
|
|
|
|
|
|
|
|
|
@@ -67,12 +66,9 @@ public class NfcTermuxBridgeActivity extends Activity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String action = intent.getAction();
|
|
|
|
|
if (ACTION_BUILD_VIEW.equals(action)) {
|
|
|
|
|
ToastUtils.show("ACTION_BUILD_VIEW 命中");
|
|
|
|
|
onOpenTermuxProjectBuildView(intent);
|
|
|
|
|
} else if (ACTION_BUILD.equals(action)) {
|
|
|
|
|
LogUtils.d(TAG, "ACTION_BUILD 命中");
|
|
|
|
|
handleNfcIntent(intent);
|
|
|
|
|
if (ACTION_BUILD.equals(action)) {
|
|
|
|
|
ToastUtils.show("ACTION_BUILD 命中");
|
|
|
|
|
onOpenTermuxProjectBuild(intent);
|
|
|
|
|
} else {
|
|
|
|
|
LogUtils.w(TAG, "dispatchIntent() 未知 Action: " + action);
|
|
|
|
|
finish();
|
|
|
|
|
@@ -83,63 +79,63 @@ public class NfcTermuxBridgeActivity extends Activity {
|
|
|
|
|
/**
|
|
|
|
|
* 处理 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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 onOpenTermuxProjectBuildView(Intent intent) {
|
|
|
|
|
public void onOpenTermuxProjectBuild(Intent intent) {
|
|
|
|
|
LogUtils.d(TAG, "onOpenTermuxProjectBuildView() 调用");
|
|
|
|
|
if (intent == null) {
|
|
|
|
|
LogUtils.w(TAG, "onOpenTermuxProjectBuildView() intent 为空");
|
|
|
|
|
@@ -171,7 +167,7 @@ public class NfcTermuxBridgeActivity extends Activity {
|
|
|
|
|
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("BuildWinBoLLProjectView.sh").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(" ");
|
|
|
|
|
@@ -216,18 +212,18 @@ public class NfcTermuxBridgeActivity extends Activity {
|
|
|
|
|
/**
|
|
|
|
|
* 内部测试方法:发送 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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// ========================= 工具方法 =========================
|
|
|
|
|
/**
|
|
|
|
|
|