Skip to content

Commit 44c66d8

Browse files
.
1 parent 6cf0b2f commit 44c66d8

File tree

58 files changed

+11574
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+11574
-4
lines changed

core/main/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ dependencies {
103103
api(libs.ui.graphics)
104104
api(libs.material3)
105105
api(libs.navigation.compose)
106-
api(libs.terminal.view)
107-
api(libs.terminal.emulator)
106+
api(project(":core:terminal-view"))
107+
api(project(":core:terminal-emulator"))
108108
api(libs.utilcode)
109109
//api(libs.commons.net)
110110
api(libs.okhttp)
111111
api(libs.anrwatchdog)
112112
api(libs.androidx.palette)
113113
api(libs.accompanist.systemuicontroller)
114+
// api(libs.termux.shared)
114115

115116
api(project(":core:resources"))
116117
api(project(":core:components"))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.rk.terminal.service
2+
3+
import android.app.Service
4+
import android.content.Intent
5+
import android.os.IBinder
6+
7+
class RunCommandService : Service() {
8+
override fun onBind(intent: Intent?): IBinder? {
9+
TODO("Not yet implemented")
10+
}
11+
}

core/main/src/main/java/com/rk/terminal/ui/activities/terminal/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.rk.terminal.ui.activities.terminal
22

3+
import android.app.Activity
4+
import android.app.PendingIntent
35
import android.content.ComponentName
46
import android.content.Context
57
import android.content.Intent
@@ -81,5 +83,9 @@ class MainActivity : ComponentActivity() {
8183
override fun onCreate(savedInstanceState: Bundle?) {
8284
super.onCreate(savedInstanceState)
8385
enableEdgeToEdge()
86+
87+
if (intent.hasExtra("awake_intent")){
88+
moveTaskToBack(true)
89+
}
8490
}
8591
}

core/main/src/main/java/com/rk/terminal/ui/screens/terminal/TerminalBackEnd.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ class TerminalBackEnd(val terminal: TerminalView,val activity: MainActivity) : T
4444
ClipboardUtils.copyText("Terminal", text)
4545
}
4646

47-
override fun onPasteTextFromClipboard(session: TerminalSession) {
47+
override fun onPasteTextFromClipboard(session: TerminalSession?) {
4848
val clip = ClipboardUtils.getText().toString()
4949
if (clip.trim { it <= ' ' }.isNotEmpty() && terminal.mEmulator != null) {
5050
terminal.mEmulator.paste(clip)
5151
}
5252
}
53-
53+
54+
override fun setTerminalShellPid(
55+
session: TerminalSession,
56+
pid: Int
57+
) {}
58+
59+
5460
override fun onBell(session: TerminalSession) {
5561
if (Settings.bell){
5662
activity.lifecycleScope.launch{
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'maven-publish'
3+
4+
android {
5+
compileSdkVersion 35
6+
ndkVersion = "27.2.12479018"
7+
namespace = "com.termux.terminal"
8+
9+
defaultConfig {
10+
minSdkVersion 26
11+
externalNativeBuild {
12+
ndkBuild {
13+
cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
14+
}
15+
}
16+
17+
ndk {
18+
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
19+
}
20+
}
21+
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26+
}
27+
}
28+
29+
externalNativeBuild {
30+
ndkBuild {
31+
path "src/main/jni/Android.mk"
32+
}
33+
}
34+
35+
compileOptions {
36+
sourceCompatibility JavaVersion.VERSION_1_8
37+
targetCompatibility JavaVersion.VERSION_1_8
38+
}
39+
40+
testOptions {
41+
unitTests.returnDefaultValues = true
42+
}
43+
}
44+
45+
tasks.withType(Test) {
46+
testLogging {
47+
events "started", "passed", "skipped", "failed"
48+
}
49+
}
50+
51+
dependencies {
52+
implementation "androidx.annotation:annotation:1.3.0"
53+
testImplementation "junit:junit:4.13.2"
54+
}
55+
56+
task sourceJar(type: Jar) {
57+
from android.sourceSets.main.java.srcDirs
58+
archiveClassifier.set("sources")
59+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/fornwall/lib/android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest>
2+
</manifest>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.termux.terminal;
2+
3+
/** A circular byte buffer allowing one producer and one consumer thread. */
4+
final class ByteQueue {
5+
6+
private final byte[] mBuffer;
7+
private int mHead;
8+
private int mStoredBytes;
9+
private boolean mOpen = true;
10+
11+
public ByteQueue(int size) {
12+
mBuffer = new byte[size];
13+
}
14+
15+
public synchronized void close() {
16+
mOpen = false;
17+
notify();
18+
}
19+
20+
public synchronized int read(byte[] buffer, boolean block) {
21+
while (mStoredBytes == 0 && mOpen) {
22+
if (block) {
23+
try {
24+
wait();
25+
} catch (InterruptedException e) {
26+
// Ignore.
27+
}
28+
} else {
29+
return 0;
30+
}
31+
}
32+
if (!mOpen) return -1;
33+
34+
int totalRead = 0;
35+
int bufferLength = mBuffer.length;
36+
boolean wasFull = bufferLength == mStoredBytes;
37+
int length = buffer.length;
38+
int offset = 0;
39+
while (length > 0 && mStoredBytes > 0) {
40+
int oneRun = Math.min(bufferLength - mHead, mStoredBytes);
41+
int bytesToCopy = Math.min(length, oneRun);
42+
System.arraycopy(mBuffer, mHead, buffer, offset, bytesToCopy);
43+
mHead += bytesToCopy;
44+
if (mHead >= bufferLength) mHead = 0;
45+
mStoredBytes -= bytesToCopy;
46+
length -= bytesToCopy;
47+
offset += bytesToCopy;
48+
totalRead += bytesToCopy;
49+
}
50+
if (wasFull) notify();
51+
return totalRead;
52+
}
53+
54+
/**
55+
* Attempt to write the specified portion of the provided buffer to the queue.
56+
* <p/>
57+
* Returns whether the output was totally written, false if it was closed before.
58+
*/
59+
public boolean write(byte[] buffer, int offset, int lengthToWrite) {
60+
if (lengthToWrite + offset > buffer.length) {
61+
throw new IllegalArgumentException("length + offset > buffer.length");
62+
} else if (lengthToWrite <= 0) {
63+
throw new IllegalArgumentException("length <= 0");
64+
}
65+
66+
final int bufferLength = mBuffer.length;
67+
68+
synchronized (this) {
69+
while (lengthToWrite > 0) {
70+
while (bufferLength == mStoredBytes && mOpen) {
71+
try {
72+
wait();
73+
} catch (InterruptedException e) {
74+
// Ignore.
75+
}
76+
}
77+
if (!mOpen) return false;
78+
final boolean wasEmpty = mStoredBytes == 0;
79+
int bytesToWriteBeforeWaiting = Math.min(lengthToWrite, bufferLength - mStoredBytes);
80+
lengthToWrite -= bytesToWriteBeforeWaiting;
81+
82+
while (bytesToWriteBeforeWaiting > 0) {
83+
int tail = mHead + mStoredBytes;
84+
int oneRun;
85+
if (tail >= bufferLength) {
86+
// Buffer: [.............]
87+
// ________________H_______T
88+
// =>
89+
// Buffer: [.............]
90+
// ___________T____H
91+
// onRun= _____----_
92+
tail = tail - bufferLength;
93+
oneRun = mHead - tail;
94+
} else {
95+
oneRun = bufferLength - tail;
96+
}
97+
int bytesToCopy = Math.min(oneRun, bytesToWriteBeforeWaiting);
98+
System.arraycopy(buffer, offset, mBuffer, tail, bytesToCopy);
99+
offset += bytesToCopy;
100+
bytesToWriteBeforeWaiting -= bytesToCopy;
101+
mStoredBytes += bytesToCopy;
102+
}
103+
if (wasEmpty) notify();
104+
}
105+
}
106+
return true;
107+
}
108+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.termux.terminal;
2+
3+
/**
4+
* Native methods for creating and managing pseudoterminal subprocesses. C code is in jni/termux.c.
5+
*/
6+
final class JNI {
7+
8+
static {
9+
System.loadLibrary("termux");
10+
}
11+
12+
/**
13+
* Create a subprocess. Differs from {@link ProcessBuilder} in that a pseudoterminal is used to communicate with the
14+
* subprocess.
15+
* <p/>
16+
* Callers are responsible for calling {@link #close(int)} on the returned file descriptor.
17+
*
18+
* @param cmd The command to execute
19+
* @param cwd The current working directory for the executed command
20+
* @param args An array of arguments to the command
21+
* @param envVars An array of strings of the form "VAR=value" to be added to the environment of the process
22+
* @param processId A one-element array to which the process ID of the started process will be written.
23+
* @return the file descriptor resulting from opening /dev/ptmx master device. The sub process will have opened the
24+
* slave device counterpart (/dev/pts/$N) and have it as stdint, stdout and stderr.
25+
*/
26+
public static native int createSubprocess(String cmd, String cwd, String[] args, String[] envVars, int[] processId, int rows, int columns, int cellWidth, int cellHeight);
27+
28+
/** Set the window size for a given pty, which allows connected programs to learn how large their screen is. */
29+
public static native void setPtyWindowSize(int fd, int rows, int cols, int cellWidth, int cellHeight);
30+
31+
/**
32+
* Causes the calling thread to wait for the process associated with the receiver to finish executing.
33+
*
34+
* @return if >= 0, the exit status of the process. If < 0, the signal causing the process to stop negated.
35+
*/
36+
public static native int waitFor(int processId);
37+
38+
/** Close a file descriptor through the close(2) system call. */
39+
public static native void close(int fileDescriptor);
40+
41+
}

0 commit comments

Comments
 (0)