Changed: Refactor am socket server

The `AmSocketServer` now handles the entire logic for processing of am commands sent by clients and its results. This can be used by other apps as well to run their own am servers. The server started by `termux-app` will be managed by `TermuxAmSocketServer`. Read their javadocs for details.

The extended implementation `TermuxAmSocketServerClient` of `AmSocketServer.AmSocketServerClient`/`ILocalSocketManager` will also send a plugin error notification for all errors to the user instead of just logging to logcat since users are not very good at checking those, this should save dev time debugging problems. We may need to ignore notifications for some errors like broken pipe, based on their `Error` objects if they are normally expected, this requires further investigation.

The `TERMUX_APP_AM_SOCKET_SERVER_ENABLED` env variable will also be exported for all shell sessions and tasks for whether the server was successfully started on app startup. The user can disable the server by adding "run-termux-am-socket-server=false" to the "~/.termux/termux.properties" as implemented in 5f8a9222. The env variable will be checked by `$PREFIX/bin/termux-am` before attempting to connect.

The new path for the server socket is `/data/data/com.termux/files/apps/termux-app/termux-am/am.sock` as per `TERMUX_APP.APPS_DIR_PATH` added in bcd8f4c4.
This commit is contained in:
agnostic-apollo
2022-04-18 04:49:47 +05:00
parent 2aa7f43d1c
commit 53f26c9659
8 changed files with 482 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ import java.util.Formatter;
import java.util.List;
/*
* Version: v0.40.0
* Version: v0.41.0
* SPDX-License-Identifier: MIT
*
* Changelog
@@ -236,6 +236,9 @@ import java.util.List;
*
* - 0.40.0 (2022-04-17)
* - Added `TERMUX_APPS_DIR_PATH` and `TERMUX_APP.APPS_DIR_PATH`.
*
* - 0.41.0 (2022-04-17)
* - Added `TERMUX_APP.TERMUX_AM_SOCKET_FILE_PATH`.
*/
/**
@@ -883,6 +886,9 @@ public final class TermuxConstants {
/** Termux apps directory path */
public static final String APPS_DIR_PATH = TERMUX_APPS_DIR_PATH + "/termux-app"; // Default: "/data/data/com.termux/files/apps/termux-app"
/** termux-am socket file path */
public static final String TERMUX_AM_SOCKET_FILE_PATH = APPS_DIR_PATH + "/termux-am/am.sock"; // Default: "/data/data/com.termux/files/apps/termux-app/termux-am/am.sock"
/** Termux app core activity name. */
public static final String TERMUX_ACTIVITY_NAME = TERMUX_PACKAGE_NAME + ".app.TermuxActivity"; // Default: "com.termux.app.TermuxActivity"