Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e73a1ca

Browse files
committed
Added support for PulseAudio
1 parent 5ae610d commit e73a1ca

34 files changed

+231
-135
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ out/
1515
# Gradle files
1616
.gradle/
1717
build/
18+
release/
1819

1920
# Local configuration file (sdk path, etc)
2021
local.properties

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog (English)
22
===================
33

4+
2.0.6
5+
Improved mount and unmount functions
6+
Added support for PulseAudio
7+
48
2.0.5
59
Enabled journal for FS ext3/4, ext2 without journal
610
Added an attempt to re-unmount in case of failure
@@ -391,6 +395,10 @@ Updated list packages of base system installation
391395
История изменений (Русский)
392396
===========================
393397

398+
2.0.6
399+
Изменен подход к монтированию и размонтированию контейнера
400+
Добавлена поддержка PulseAudio
401+
394402
2.0.5
395403
Включено журналирование для ФС ext3/4, без журналирования ext2
396404
Добавлена попытка повторного размонтирования в случае неудачи

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId 'ru.meefik.linuxdeploy'
99
minSdkVersion 10
1010
targetSdkVersion 25
11-
versionCode 231
12-
versionName "2.0.5"
11+
versionCode 233
12+
versionName "2.0.6"
1313
}
1414
buildTypes {
1515
release {

app/src/main/java/ru/meefik/linuxdeploy/ActionReceiver.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import android.app.NotificationManager;
44
import android.content.BroadcastReceiver;
5-
import android.content.ComponentName;
65
import android.content.Context;
76
import android.content.Intent;
8-
import android.content.pm.PackageManager;
97
import android.support.v4.app.NotificationCompat;
108

119
public class ActionReceiver extends BroadcastReceiver {

app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.OutputStream;
1919
import java.util.ArrayList;
2020
import java.util.List;
21-
import java.util.Map;
2221

2322
class EnvUtils {
2423

@@ -293,7 +292,6 @@ public static boolean exec(final Context c, final String shell, final List<Strin
293292
}
294293
boolean result = false;
295294
OutputStream stdin = null;
296-
InputStream stdout;
297295
try {
298296
ProcessBuilder pb = new ProcessBuilder(shell);
299297
pb.directory(new File(PrefStore.getEnvDir(c)));
@@ -303,8 +301,10 @@ public static boolean exec(final Context c, final String shell, final List<Strin
303301
Process process = pb.start();
304302

305303
stdin = process.getOutputStream();
306-
stdout = process.getInputStream();
304+
final InputStream stdout = process.getInputStream();
305+
// final InputStream stderr = process.getErrorStream();
307306

307+
// params.add(0, "LD_LIBRARY_PATH=" + PrefStore.getLibsDir(c) + ":$LD_LIBRARY_PATH");
308308
params.add(0, "PATH=" + PrefStore.getBinDir(c) + ":$PATH");
309309
if (PrefStore.isTraceMode(c)) params.add(0, "set -x");
310310
params.add("exit $?");
@@ -322,12 +322,10 @@ public static boolean exec(final Context c, final String shell, final List<Strin
322322
close(os);
323323
}
324324

325-
// show stdout log
326-
final InputStream out = stdout;
327325
(new Thread() {
328326
@Override
329327
public void run() {
330-
Logger.log(c, out);
328+
Logger.log(c, stdout);
331329
}
332330
}).start();
333331

@@ -348,10 +346,8 @@ public void run() {
348346
* @return true if success
349347
*/
350348
static boolean updateEnv(final Context c) {
351-
// stop telnetd
352-
execService(c, "telnetd", "stop");
353-
//stop httpd
354-
execService(c, "httpd", "stop");
349+
// stop services
350+
execServices(c, new String[]{"telnetd", "httpd"}, "stop");
355351

356352
// extract bin assets
357353
if (!extractDir(c, PrefStore.getBinDir(c), "bin/all", "")) return false;
@@ -366,6 +362,10 @@ static boolean updateEnv(final Context c) {
366362
// make linuxdeploy script
367363
if (!makeScript(c)) return false;
368364

365+
// make etc directory
366+
File etcDir = new File(PrefStore.getEtcDir(c));
367+
etcDir.mkdirs();
368+
369369
// make tmp directory
370370
File tmpDir = new File(PrefStore.getTmpDir(c));
371371
tmpDir.mkdirs();
@@ -404,10 +404,8 @@ static boolean updateEnv(final Context c) {
404404
// update version
405405
if (!setVersion(c)) return false;
406406

407-
// start telnetd
408-
execService(c, "telnetd", "start");
409-
//start httpd
410-
execService(c, "httpd", "start");
407+
// start services
408+
execServices(c, new String[]{"telnetd", "httpd"}, "start");
411409

412410
return true;
413411
}
@@ -455,11 +453,8 @@ static boolean removeEnv(Context c) {
455453
// remove version file
456454
resetVersion(c);
457455

458-
// stop telnetd
459-
execService(c, "telnetd", "stop");
460-
461-
//stop httpd
462-
execService(c, "httpd", "stop");
456+
// stop services
457+
execServices(c, new String[]{"telnetd", "httpd"}, "stop");
463458

464459
// remove symlink
465460
File ldSymlink = new File("/system/bin/linuxdeploy");
@@ -473,14 +468,18 @@ static boolean removeEnv(Context c) {
473468
File envDir = new File(PrefStore.getEnvDir(c));
474469
cleanDirectory(envDir);
475470

476-
// clean tmp directory
477-
File tmpDir = new File(PrefStore.getTmpDir(c));
478-
cleanDirectory(tmpDir);
471+
// clean etc directory
472+
File etcDir = new File(PrefStore.getEtcDir(c));
473+
cleanDirectory(etcDir);
479474

480475
// clean bin directory
481476
File binDir = new File(PrefStore.getBinDir(c));
482477
cleanDirectory(binDir);
483478

479+
// clean tmp directory
480+
File tmpDir = new File(PrefStore.getTmpDir(c));
481+
cleanDirectory(tmpDir);
482+
484483
return true;
485484
}
486485

@@ -509,8 +508,9 @@ public static boolean cli(Context c, String cmd, String args) {
509508
/**
510509
* Execute command via service
511510
*
512-
* @param c context
513-
* @param args command and arguments
511+
* @param c context
512+
* @param cmd command
513+
* @param args arguments
514514
*/
515515
static void execService(Context c, String cmd, String args) {
516516
Intent service = new Intent(c, ExecService.class);
@@ -519,10 +519,23 @@ static void execService(Context c, String cmd, String args) {
519519
c.startService(service);
520520
}
521521

522+
/**
523+
* Execute commands via service
524+
*
525+
* @param c context
526+
* @param commands commands
527+
* @param args command and arguments
528+
*/
529+
static void execServices(Context c, String[] commands, String args) {
530+
for (String cmd : commands) {
531+
execService(c, cmd, args);
532+
}
533+
}
534+
522535
/**
523536
* Start/stop telnetd daemon
524537
*
525-
* @param c context
538+
* @param c context
526539
* @param cmd command: start, stop or restart
527540
* @return true if success
528541
*/
@@ -554,7 +567,7 @@ static boolean telnetd(Context c, String cmd) {
554567
/**
555568
* Start/stop httpd daemon
556569
*
557-
* @param c context
570+
* @param c context
558571
* @param cmd command: start, stop or restart
559572
* @return true if success
560573
*/
@@ -568,14 +581,13 @@ static boolean httpd(Context c, String cmd) {
568581
if (cmd.equals("stop")) break;
569582
case "start":
570583
if (!PrefStore.isHttp(c)) break;
571-
File conf = PrefStore.getHttpConfFile(c);
572-
EnvUtils.makeHttpdConf(c, conf);
584+
makeHttpdConf(c);
573585
params.add("pgrep httpd >/dev/null && exit");
574586
params.add("export WS_SHELL=\"telnet 127.0.0.1 " + PrefStore.getTelnetPort(c) + "\"");
575587
params.add("export ENV_DIR=\"" + PrefStore.getEnvDir(c) + "\"");
576588
params.add("export HOME=\"" + PrefStore.getEnvDir(c) + "\"");
577589
params.add("cd " + PrefStore.getWebDir(c));
578-
params.add("httpd " + " -p " + PrefStore.getHttpPort(c) + " -c " + conf);
590+
params.add("httpd " + " -p " + PrefStore.getHttpPort(c) + " -c " + PrefStore.getEtcDir(c) + "/httpd.conf");
579591
}
580592
return params.size() > 0 && exec(c, "sh", params);
581593
}
@@ -586,12 +598,13 @@ static boolean httpd(Context c, String cmd) {
586598
* @param c context
587599
* @return true if success
588600
*/
589-
private static boolean makeHttpdConf(Context c, File conf) {
601+
private static boolean makeHttpdConf(Context c) {
590602
boolean result = false;
591603
BufferedWriter bw = null;
592604
try {
593-
bw = new BufferedWriter(new FileWriter(conf));
594-
for(String part: PrefStore.getHttpConf(c).split(" ")) {
605+
String f = PrefStore.getEtcDir(c) + "/httpd.conf";
606+
bw = new BufferedWriter(new FileWriter(f));
607+
for (String part : PrefStore.getHttpConf(c).split(" ")) {
595608
bw.write(part + "\n");
596609
}
597610
result = true;

app/src/main/java/ru/meefik/linuxdeploy/Logger.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44

55
import java.io.BufferedReader;
6-
import java.io.BufferedWriter;
76
import java.io.Closeable;
87
import java.io.File;
98
import java.io.FileWriter;
@@ -59,8 +58,6 @@ private static synchronized void appendMessage(Context c, final String msg) {
5958
}
6059
// show protocol
6160
show();
62-
// write log
63-
if (PrefStore.isLogger(c)) write(c, msg);
6461
}
6562

6663
/**
@@ -125,25 +122,6 @@ private static void close(Closeable c) {
125122
}
126123
}
127124

128-
/**
129-
* Write to log file
130-
*
131-
* @param c context
132-
* @param msg message
133-
*/
134-
private static void write(Context c, String msg) {
135-
String logFile = PrefStore.getLogFile(c);
136-
BufferedWriter writer = null;
137-
try {
138-
writer = new BufferedWriter(new FileWriter(logFile, true));
139-
writer.write(msg);
140-
} catch (IOException e) {
141-
// e.printStackTrace();
142-
} finally {
143-
close(writer);
144-
}
145-
}
146-
147125
/**
148126
* Append stream messages to protocol
149127
*
@@ -152,17 +130,23 @@ private static void write(Context c, String msg) {
152130
*/
153131
static void log(Context c, InputStream stream) {
154132
BufferedReader reader = null;
133+
FileWriter writer = null;
155134
try {
156135
reader = new BufferedReader(new InputStreamReader(stream));
136+
if (PrefStore.isLogger(c)) {
137+
writer = new FileWriter(PrefStore.getLogFile(c));
138+
}
157139
int n;
158140
char[] buffer = new char[1024];
159141
while ((n = reader.read(buffer)) != -1) {
160142
String msg = String.valueOf(buffer, 0, n);
161143
appendMessage(c, msg);
144+
if (writer != null) writer.write(msg);
162145
}
163146
} catch (IOException e) {
164147
e.printStackTrace();
165148
} finally {
149+
close(writer);
166150
close(reader);
167151
close(stream);
168152
}

app/src/main/java/ru/meefik/linuxdeploy/MainActivity.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public void onCreate(Bundle savedInstanceState) {
7474

7575
if (EnvUtils.isLatestVersion(this)) {
7676
// start telnetd
77-
EnvUtils.execService(getBaseContext(), "telnetd", "start");
78-
// start httpd
79-
EnvUtils.execService(getBaseContext(), "httpd", "start");
77+
EnvUtils.execServices(getBaseContext(), new String[]{"telnetd", "httpd"}, "start");
8078
} else {
8179
// Update ENV
8280
new UpdateEnvTask(this).execute();
@@ -176,8 +174,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
176174
case R.id.nav_exit:
177175
if (wifiLock.isHeld()) wifiLock.release();
178176
if (wakeLock.isHeld()) wakeLock.release();
179-
EnvUtils.execService(getBaseContext(), "telnetd", "stop");
180-
EnvUtils.execService(getBaseContext(), "httpd", "stop");
177+
EnvUtils.execServices(getBaseContext(), new String[]{"telnetd", "httpd"}, "stop");
181178
PrefStore.hideNotification(getBaseContext());
182179
finish();
183180
break;
@@ -214,16 +211,14 @@ public void onResume() {
214211
// WiFi lock
215212
if (PrefStore.isWifiLock(this)) {
216213
if (!wifiLock.isHeld()) wifiLock.acquire();
217-
}
218-
else {
214+
} else {
219215
if (wifiLock.isHeld()) wifiLock.release();
220216
}
221217

222218
// Wake lock
223219
if (PrefStore.isWakeLock(this)) {
224220
if (!wakeLock.isHeld()) wakeLock.acquire();
225-
}
226-
else {
221+
} else {
227222
if (wakeLock.isHeld()) wakeLock.release();
228223
}
229224
}
@@ -445,7 +440,7 @@ private void openTerminal() {
445440
intent_terminal.putExtra("jackpal.androidterm.iInitialCommand",
446441
PrefStore.getTerminalCmd(this));
447442
startActivity(intent_terminal);
448-
} catch(Exception e) {
443+
} catch (Exception e) {
449444
Toast.makeText(this, R.string.toast_terminal_error, Toast.LENGTH_SHORT).show();
450445
}
451446
}

app/src/main/java/ru/meefik/linuxdeploy/NetworkReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class NetworkReceiver extends BroadcastReceiver {
1212
public void onReceive(final Context context, Intent intent) {
1313
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
1414
ConnectivityManager cm =
15-
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
15+
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
1616

1717
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
1818
boolean isConnected = false;

app/src/main/java/ru/meefik/linuxdeploy/ParamUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static Map<String, String> readConf(File confFile) {
5151
String[] pair = line.split("=");
5252
String key = pair[0];
5353
String value = pair[1];
54-
map.put(key, value.replaceAll("\"",""));
54+
map.put(key, value.replaceAll("\"", ""));
5555
}
5656
}
5757
} catch (Exception e) {
@@ -70,7 +70,7 @@ private static boolean writeConf(Map<String, String> map, File confFile) {
7070
for (Map.Entry<String, String> entry : map.entrySet()) {
7171
String key = entry.getKey();
7272
String value = entry.getValue();
73-
bw.write(key + "=\"" + value+"\"");
73+
bw.write(key + "=\"" + value + "\"");
7474
bw.newLine();
7575
}
7676
result = true;

0 commit comments

Comments
 (0)