-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME
135 lines (114 loc) · 5.55 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
ABOUT
Transmission is a fast, easy, and free BitTorrent client.
Visit https://transmissionbt.com/ for more information.
This repository is an Android port of the transmission daemon version 2.94.
Modifications have been made to the source code of transmission and dependency
libraries in order to make this compile without errors.
It provides a nice interactive build script and supports cross compiling to ARM and X86 android.
BUILDING
Download and extract the latest Android NDK from https://developer.android.com/ndk/downloads/
I already had revision 17c and it worked fine.
Clone this repository.
$ git clone https://github.com/hugorosario/transmission-android.git
Edit the "build.sh" script inside the "builder" folder and set your NDK_ROOT directory to where you extracted it.
For example, export NDK_ROOT=/home/dev/android-ndk
Run the interactive build script.
$ ./build.sh
Select architecture (ARM or X86) to build the toolchain.
Select "Build all (dependencies + transmission)".
If everything went good, you should have a transmission-daemon binary in your toolchain sysroot/usr/bin folder.
RUNNING
Since this is a binary executable and not an APK, it needs to be launched from JAVA code.
This means you need to build and APK to start/stop the daemon.
In order to execute the daemon, you have to copy it to the app private space and make it executable.
This is required because Android does not allow launching executables located on the SD card.
Here is some code that extracts the binary from the RAW folder into getFilesDir() location
and makes it executable:
static boolean initialize(Context context) {
try {
initialized = false;
String appFileDirectory = context.getFilesDir().getParent();
binary = new File(appFileDirectory + "/transmissiond");
extractResource(context, R.raw.transmission_x86, binary);
if (binary.exists())
initialized = binary.setExecutable(true);
} catch (Exception e) {
e.printStackTrace();
}
return initialized;
}
static void extractResource(Context context, int id, File dest){
try {
InputStream ins = context.getResources().openRawResource(id);
final byte[] buffer = new byte[ins.available()];
ins.read(buffer);
ins.close();
if (dest.exists())
dest.delete();
FileOutputStream fos = new FileOutputStream(dest);
fos.write(buffer);
fos.close();
}catch (Exception e){
e.printStackTrace();
}
}
Here is some code that might help launching the daemon (many parameters are missing from this sample code):
public static void startDaemon(final TransmissionListener listener){
new Thread(new Runnable() {
@Override
public void run() {
try {
if (isInitialized()){
process = new ProcessBuilder().command(binary.getAbsolutePath(),"-f").redirectErrorStream(true).start();
listener.onStatusUpdated(false, "transmission-daemon started!");
Thread readThread = new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while (!Thread.currentThread().isInterrupted()) {
if (bufferedReader.ready()) {
String line = bufferedReader.readLine();
listener.onLog(line);
}
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
readThread.start();
Thread errorThread = new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while (!Thread.currentThread().isInterrupted()) {
if (bufferedReader.ready()) {
String line = bufferedReader.readLine();
listener.onError(line);
}
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
errorThread.start();
process.waitFor();
readThread.interrupt();
errorThread.interrupt();
process = null;
listener.onStatusUpdated(false, "transmission-daemon stopped!");
}
} catch (Exception e) {
e.printStackTrace();
listener.onStatusUpdated(false, "FATAL ERROR : " + e.getMessage());
}
}
}).start();
}
TODO
I will soon add a sample APK that starts/stops the daemon and has a nice helper class for transmission settings.