From 766e5a55f0dd47624ffc3ddc598d7a4ced466ec9 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Wed, 29 Jul 2015 14:04:54 +0200 Subject: [PATCH] improved daemon status detection --- .../main/java/net/nzbget/nzbget/Daemon.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/nzbget/nzbget/Daemon.java b/app/src/main/java/net/nzbget/nzbget/Daemon.java index 938378e..2653ee9 100644 --- a/app/src/main/java/net/nzbget/nzbget/Daemon.java +++ b/app/src/main/java/net/nzbget/nzbget/Daemon.java @@ -2,7 +2,11 @@ import android.util.Log; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; public class Daemon { @@ -27,13 +31,33 @@ public Status status() { return Status.STATUS_NOTINSTALLED; } - else if (new File("/data/data/net.nzbget.nzbget/nzbget/nzbget.lock").exists()) + + File lockFile = new File("/data/data/net.nzbget.nzbget/nzbget/nzbget.lock"); + if (!lockFile.exists()) { - return Status.STATUS_RUNNING; - } - else { return Status.STATUS_STOPPED; } + + try + { + Process process = Runtime.getRuntime().exec("ps nzbget"); + BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); + int num = 0; + while (br.readLine() != null) + { + num++; + } + if (num > 1) + { + return Status.STATUS_RUNNING; + } + } + catch (IOException e) + { + // ignore + } + + return Status.STATUS_STOPPED; } public boolean exec(String cmdLine)