mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-29 15:51:17 +00:00
Fix shutdown during pending startup of the runtime (#34)
This commit is contained in:
parent
8591f4245f
commit
c44996012a
2 changed files with 17 additions and 6 deletions
|
@ -266,7 +266,7 @@ public class SyncthingRunnable implements Runnable {
|
|||
* Look for running libsyncthing.so processes and return an array
|
||||
* containing the PIDs of found instances.
|
||||
*/
|
||||
private List<String> getSyncthingPIDs() {
|
||||
private List<String> getSyncthingPIDs(Boolean enableLog) {
|
||||
List<String> syncthingPIDs = new ArrayList<String>();
|
||||
Process ps = null;
|
||||
DataOutputStream psOut = null;
|
||||
|
@ -283,7 +283,9 @@ public class SyncthingRunnable implements Runnable {
|
|||
while ((line = br.readLine()) != null) {
|
||||
if (line.contains(Constants.FILENAME_SYNCTHING_BINARY)) {
|
||||
String syncthingPID = line.trim().split("\\s+")[1];
|
||||
Log.v(TAG, "getSyncthingPIDs: Found process PID [" + syncthingPID + "]");
|
||||
if (enableLog) {
|
||||
Log.v(TAG, "getSyncthingPIDs: Found process PID [" + syncthingPID + "]");
|
||||
}
|
||||
syncthingPIDs.add(syncthingPID);
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +332,7 @@ public class SyncthingRunnable implements Runnable {
|
|||
return;
|
||||
}
|
||||
|
||||
List<String> syncthingPIDs = getSyncthingPIDs();
|
||||
List<String> syncthingPIDs = getSyncthingPIDs(false);
|
||||
if (syncthingPIDs.isEmpty()) {
|
||||
Log.i(TAG_NICE, "Found no running instances of " + Constants.FILENAME_SYNCTHING_BINARY);
|
||||
return;
|
||||
|
@ -350,7 +352,7 @@ public class SyncthingRunnable implements Runnable {
|
|||
*/
|
||||
public void killSyncthing() {
|
||||
int exitCode;
|
||||
List<String> syncthingPIDs = getSyncthingPIDs();
|
||||
List<String> syncthingPIDs = getSyncthingPIDs(true);
|
||||
if (syncthingPIDs.isEmpty()) {
|
||||
Log.d(TAG, "killSyncthing: Found no running instances of " + Constants.FILENAME_SYNCTHING_BINARY);
|
||||
return;
|
||||
|
@ -369,7 +371,7 @@ public class SyncthingRunnable implements Runnable {
|
|||
* Wait for the syncthing instance to end.
|
||||
*/
|
||||
Log.v(TAG, "Waiting for all syncthing instances to end ...");
|
||||
while (!getSyncthingPIDs().isEmpty()) {
|
||||
while (!getSyncthingPIDs(false).isEmpty()) {
|
||||
SystemClock.sleep(50);
|
||||
}
|
||||
Log.v(TAG, "killSyncthing: Complete.");
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.SharedPreferences;
|
|||
import android.Manifest;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
@ -494,7 +495,15 @@ public class SyncthingService extends Service {
|
|||
* Sets {@link #mCurrentState} to newState, and calls onKilledListener once Syncthing is killed.
|
||||
*/
|
||||
private void shutdown(State newState, OnSyncthingKilled onKilledListener) {
|
||||
Log.i(TAG, "Shutting down background service");
|
||||
if (mCurrentState == State.STARTING) {
|
||||
Log.w(TAG, "Deferring shutdown until State.STARTING was left");
|
||||
mHandler.postDelayed(() -> {
|
||||
shutdown(newState, onKilledListener);
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Shutting down");
|
||||
synchronized(mStateLock) {
|
||||
onServiceStateChange(newState);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue