Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins without shared UID #2921

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {

implementation project(":terminal-view")
implementation project(":termux-shared")
implementation project(":plugin-aidl")
}

defaultConfig {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
android:label="@string/permission_run_command_label"
android:protectionLevel="dangerous" />

<permission
android:name="${TERMUX_PACKAGE_NAME}.permission.TERMUX_PLUGIN"
android:description="@string/permission_plugin_description"
android:icon="@mipmap/ic_launcher"
android:label="@string/permission_plugin_label"
android:protectionLevel="dangerous" />

<permission
android:name="${TERMUX_PACKAGE_NAME}.permission.TERMUX_SIGNATURE"
android:protectionLevel="signature" />
<uses-permission android:name="${TERMUX_PACKAGE_NAME}.permission.TERMUX_SIGNATURE" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down Expand Up @@ -207,6 +219,10 @@
</intent-filter>
</service>

<service
android:name=".app.plugin.PluginService"
android:exported="true"
android:permission="${TERMUX_PACKAGE_NAME}.permission.TERMUX_PLUGIN"/>

<!-- This (or rather, value 2.1 or higher) is needed to make the Samsung Galaxy S8 mark the
app with "This app is optimized to run in full screen." -->
Expand Down
36 changes: 32 additions & 4 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.Process;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -22,6 +23,7 @@
import com.termux.app.event.SystemEventReceiver;
import com.termux.app.terminal.TermuxTerminalSessionActivityClient;
import com.termux.app.terminal.TermuxTerminalSessionServiceClient;
import com.termux.shared.shell.command.runner.nativerunner.NativeShell;
import com.termux.shared.termux.plugins.TermuxPluginUtils;
import com.termux.shared.data.IntentUtils;
import com.termux.shared.net.uri.UriUtils;
Expand Down Expand Up @@ -68,7 +70,7 @@
public final class TermuxService extends Service implements AppShell.AppShellClient, TermuxSession.TermuxSessionClient {

/** This service is only bound from inside the same process and never uses IPC. */
class LocalBinder extends Binder {
public class LocalBinder extends Binder {
public final TermuxService service = TermuxService.this;
}

Expand Down Expand Up @@ -287,6 +289,11 @@ private synchronized void killAllTermuxExecutionCommands() {
else
mShellManager.mTermuxTasks.remove(termuxTasks.get(i));
}

List<NativeShell> termuxNativeTasks = new ArrayList<>(mShellManager.mTermuxNativeTasks);
for (int i = 0; i < termuxNativeTasks.size(); i++) {
termuxNativeTasks.get(i).kill(Process.SIGNAL_KILL);
}

for (int i = 0; i < pendingPluginExecutionCommands.size(); i++) {
ExecutionCommand executionCommand = pendingPluginExecutionCommands.get(i);
Expand Down Expand Up @@ -423,8 +430,29 @@ else if (Runner.TERMINAL_SESSION.equalsRunner(executionCommand.runner))
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
}
}



/**
* Executes a NativeShell as a TermuxTask.
*/
public NativeShell executeNativeShell(ExecutionCommand executionCommand, String[] environment, NativeShell.Client client) {
final NativeShell[] shell = new NativeShell[1];
shell[0] = new NativeShell(executionCommand, (exitCode, error) -> {
mHandler.post(() -> {
mShellManager.mTermuxNativeTasks.remove(shell[0]);
updateNotification();
});
client.terminated(exitCode, error);
}, environment);
mShellManager.mTermuxNativeTasks.add(shell[0]);

if (shell[0].execute()) {
updateNotification();
} else {
// gets removed automatically by the callback
return null;
}
return shell[0];
}



Expand Down Expand Up @@ -789,7 +817,7 @@ private Notification buildNotification() {

// Set notification text
int sessionCount = getTermuxSessionsSize();
int taskCount = mShellManager.mTermuxTasks.size();
int taskCount = mShellManager.mTermuxTasks.size() + mShellManager.mTermuxNativeTasks.size();
String notificationText = sessionCount + " session" + (sessionCount == 1 ? "" : "s");
if (taskCount > 0) {
notificationText += ", " + taskCount + " task" + (taskCount == 1 ? "" : "s");
Expand Down
Loading
Loading