Skip to content

Commit

Permalink
Added support for PulseAudio
Browse files Browse the repository at this point in the history
  • Loading branch information
meefik committed Feb 17, 2018
1 parent 5ae610d commit e73a1ca
Show file tree
Hide file tree
Showing 34 changed files with 231 additions and 135 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ out/
# Gradle files
.gradle/
build/
release/

# Local configuration file (sdk path, etc)
local.properties
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog (English)
===================

2.0.6
Improved mount and unmount functions
Added support for PulseAudio

2.0.5
Enabled journal for FS ext3/4, ext2 without journal
Added an attempt to re-unmount in case of failure
Expand Down Expand Up @@ -391,6 +395,10 @@ Updated list packages of base system installation
История изменений (Русский)
===========================

2.0.6
Изменен подход к монтированию и размонтированию контейнера
Добавлена поддержка PulseAudio

2.0.5
Включено журналирование для ФС ext3/4, без журналирования ext2
Добавлена попытка повторного размонтирования в случае неудачи
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId 'ru.meefik.linuxdeploy'
minSdkVersion 10
targetSdkVersion 25
versionCode 231
versionName "2.0.5"
versionCode 233
versionName "2.0.6"
}
buildTypes {
release {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/ru/meefik/linuxdeploy/ActionReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.NotificationCompat;

public class ActionReceiver extends BroadcastReceiver {
Expand Down
77 changes: 45 additions & 32 deletions app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

class EnvUtils {

Expand Down Expand Up @@ -293,7 +292,6 @@ public static boolean exec(final Context c, final String shell, final List<Strin
}
boolean result = false;
OutputStream stdin = null;
InputStream stdout;
try {
ProcessBuilder pb = new ProcessBuilder(shell);
pb.directory(new File(PrefStore.getEnvDir(c)));
Expand All @@ -303,8 +301,10 @@ public static boolean exec(final Context c, final String shell, final List<Strin
Process process = pb.start();

stdin = process.getOutputStream();
stdout = process.getInputStream();
final InputStream stdout = process.getInputStream();
// final InputStream stderr = process.getErrorStream();

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

// show stdout log
final InputStream out = stdout;
(new Thread() {
@Override
public void run() {
Logger.log(c, out);
Logger.log(c, stdout);
}
}).start();

Expand All @@ -348,10 +346,8 @@ public void run() {
* @return true if success
*/
static boolean updateEnv(final Context c) {
// stop telnetd
execService(c, "telnetd", "stop");
//stop httpd
execService(c, "httpd", "stop");
// stop services
execServices(c, new String[]{"telnetd", "httpd"}, "stop");

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

// make etc directory
File etcDir = new File(PrefStore.getEtcDir(c));
etcDir.mkdirs();

// make tmp directory
File tmpDir = new File(PrefStore.getTmpDir(c));
tmpDir.mkdirs();
Expand Down Expand Up @@ -404,10 +404,8 @@ static boolean updateEnv(final Context c) {
// update version
if (!setVersion(c)) return false;

// start telnetd
execService(c, "telnetd", "start");
//start httpd
execService(c, "httpd", "start");
// start services
execServices(c, new String[]{"telnetd", "httpd"}, "start");

return true;
}
Expand Down Expand Up @@ -455,11 +453,8 @@ static boolean removeEnv(Context c) {
// remove version file
resetVersion(c);

// stop telnetd
execService(c, "telnetd", "stop");

//stop httpd
execService(c, "httpd", "stop");
// stop services
execServices(c, new String[]{"telnetd", "httpd"}, "stop");

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

// clean tmp directory
File tmpDir = new File(PrefStore.getTmpDir(c));
cleanDirectory(tmpDir);
// clean etc directory
File etcDir = new File(PrefStore.getEtcDir(c));
cleanDirectory(etcDir);

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

// clean tmp directory
File tmpDir = new File(PrefStore.getTmpDir(c));
cleanDirectory(tmpDir);

return true;
}

Expand Down Expand Up @@ -509,8 +508,9 @@ public static boolean cli(Context c, String cmd, String args) {
/**
* Execute command via service
*
* @param c context
* @param args command and arguments
* @param c context
* @param cmd command
* @param args arguments
*/
static void execService(Context c, String cmd, String args) {
Intent service = new Intent(c, ExecService.class);
Expand All @@ -519,10 +519,23 @@ static void execService(Context c, String cmd, String args) {
c.startService(service);
}

/**
* Execute commands via service
*
* @param c context
* @param commands commands
* @param args command and arguments
*/
static void execServices(Context c, String[] commands, String args) {
for (String cmd : commands) {
execService(c, cmd, args);
}
}

/**
* Start/stop telnetd daemon
*
* @param c context
* @param c context
* @param cmd command: start, stop or restart
* @return true if success
*/
Expand Down Expand Up @@ -554,7 +567,7 @@ static boolean telnetd(Context c, String cmd) {
/**
* Start/stop httpd daemon
*
* @param c context
* @param c context
* @param cmd command: start, stop or restart
* @return true if success
*/
Expand All @@ -568,14 +581,13 @@ static boolean httpd(Context c, String cmd) {
if (cmd.equals("stop")) break;
case "start":
if (!PrefStore.isHttp(c)) break;
File conf = PrefStore.getHttpConfFile(c);
EnvUtils.makeHttpdConf(c, conf);
makeHttpdConf(c);
params.add("pgrep httpd >/dev/null && exit");
params.add("export WS_SHELL=\"telnet 127.0.0.1 " + PrefStore.getTelnetPort(c) + "\"");
params.add("export ENV_DIR=\"" + PrefStore.getEnvDir(c) + "\"");
params.add("export HOME=\"" + PrefStore.getEnvDir(c) + "\"");
params.add("cd " + PrefStore.getWebDir(c));
params.add("httpd " + " -p " + PrefStore.getHttpPort(c) + " -c " + conf);
params.add("httpd " + " -p " + PrefStore.getHttpPort(c) + " -c " + PrefStore.getEtcDir(c) + "/httpd.conf");
}
return params.size() > 0 && exec(c, "sh", params);
}
Expand All @@ -586,12 +598,13 @@ static boolean httpd(Context c, String cmd) {
* @param c context
* @return true if success
*/
private static boolean makeHttpdConf(Context c, File conf) {
private static boolean makeHttpdConf(Context c) {
boolean result = false;
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(conf));
for(String part: PrefStore.getHttpConf(c).split(" ")) {
String f = PrefStore.getEtcDir(c) + "/httpd.conf";
bw = new BufferedWriter(new FileWriter(f));
for (String part : PrefStore.getHttpConf(c).split(" ")) {
bw.write(part + "\n");
}
result = true;
Expand Down
28 changes: 6 additions & 22 deletions app/src/main/java/ru/meefik/linuxdeploy/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -59,8 +58,6 @@ private static synchronized void appendMessage(Context c, final String msg) {
}
// show protocol
show();
// write log
if (PrefStore.isLogger(c)) write(c, msg);
}

/**
Expand Down Expand Up @@ -125,25 +122,6 @@ private static void close(Closeable c) {
}
}

/**
* Write to log file
*
* @param c context
* @param msg message
*/
private static void write(Context c, String msg) {
String logFile = PrefStore.getLogFile(c);
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(logFile, true));
writer.write(msg);
} catch (IOException e) {
// e.printStackTrace();
} finally {
close(writer);
}
}

/**
* Append stream messages to protocol
*
Expand All @@ -152,17 +130,23 @@ private static void write(Context c, String msg) {
*/
static void log(Context c, InputStream stream) {
BufferedReader reader = null;
FileWriter writer = null;
try {
reader = new BufferedReader(new InputStreamReader(stream));
if (PrefStore.isLogger(c)) {
writer = new FileWriter(PrefStore.getLogFile(c));
}
int n;
char[] buffer = new char[1024];
while ((n = reader.read(buffer)) != -1) {
String msg = String.valueOf(buffer, 0, n);
appendMessage(c, msg);
if (writer != null) writer.write(msg);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
close(writer);
close(reader);
close(stream);
}
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/ru/meefik/linuxdeploy/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public void onCreate(Bundle savedInstanceState) {

if (EnvUtils.isLatestVersion(this)) {
// start telnetd
EnvUtils.execService(getBaseContext(), "telnetd", "start");
// start httpd
EnvUtils.execService(getBaseContext(), "httpd", "start");
EnvUtils.execServices(getBaseContext(), new String[]{"telnetd", "httpd"}, "start");
} else {
// Update ENV
new UpdateEnvTask(this).execute();
Expand Down Expand Up @@ -176,8 +174,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
case R.id.nav_exit:
if (wifiLock.isHeld()) wifiLock.release();
if (wakeLock.isHeld()) wakeLock.release();
EnvUtils.execService(getBaseContext(), "telnetd", "stop");
EnvUtils.execService(getBaseContext(), "httpd", "stop");
EnvUtils.execServices(getBaseContext(), new String[]{"telnetd", "httpd"}, "stop");
PrefStore.hideNotification(getBaseContext());
finish();
break;
Expand Down Expand Up @@ -214,16 +211,14 @@ public void onResume() {
// WiFi lock
if (PrefStore.isWifiLock(this)) {
if (!wifiLock.isHeld()) wifiLock.acquire();
}
else {
} else {
if (wifiLock.isHeld()) wifiLock.release();
}

// Wake lock
if (PrefStore.isWakeLock(this)) {
if (!wakeLock.isHeld()) wakeLock.acquire();
}
else {
} else {
if (wakeLock.isHeld()) wakeLock.release();
}
}
Expand Down Expand Up @@ -445,7 +440,7 @@ private void openTerminal() {
intent_terminal.putExtra("jackpal.androidterm.iInitialCommand",
PrefStore.getTerminalCmd(this));
startActivity(intent_terminal);
} catch(Exception e) {
} catch (Exception e) {
Toast.makeText(this, R.string.toast_terminal_error, Toast.LENGTH_SHORT).show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NetworkReceiver extends BroadcastReceiver {
public void onReceive(final Context context, Intent intent) {
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = false;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ru/meefik/linuxdeploy/ParamUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static Map<String, String> readConf(File confFile) {
String[] pair = line.split("=");
String key = pair[0];
String value = pair[1];
map.put(key, value.replaceAll("\"",""));
map.put(key, value.replaceAll("\"", ""));
}
}
} catch (Exception e) {
Expand All @@ -70,7 +70,7 @@ private static boolean writeConf(Map<String, String> map, File confFile) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
bw.write(key + "=\"" + value+"\"");
bw.write(key + "=\"" + value + "\"");
bw.newLine();
}
result = true;
Expand Down
Loading

0 comments on commit e73a1ca

Please sign in to comment.