From a64cf6c0bdad6610b325c6edf32ba4f6133f005a Mon Sep 17 00:00:00 2001 From: Caio Faustino Date: Fri, 20 Dec 2019 00:43:29 +0100 Subject: [PATCH 1/2] Avoid infinite loop if daemon is not responding. --- .../main/java/com/greenaddress/abcore/RPCIntentService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java b/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java index e8286faf..1f0a9b01 100755 --- a/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java +++ b/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java @@ -177,6 +177,11 @@ protected void onHandleIntent(final Intent intent) { getRpc().stop(); break; } catch (final BitcoinRPCException | IOException e) { + if (e instanceof BitcoinRPCException && ((BitcoinRPCException) e).getResponse() == null) { + Log.e(TAG, "daemon not responding, already stopped"); + broadcastError(e); + break; + } try { Thread.sleep(200); } catch (final InterruptedException e1) { From 932175ebec227869590c15f67d500b686b8e65ac Mon Sep 17 00:00:00 2001 From: Caio Faustino Date: Tue, 24 Dec 2019 15:08:51 +0100 Subject: [PATCH 2/2] Broadcast stop command. --- .../java/com/greenaddress/abcore/MainActivity.java | 7 +++++++ .../java/com/greenaddress/abcore/RPCIntentService.java | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/src/main/java/com/greenaddress/abcore/MainActivity.java b/app/src/main/java/com/greenaddress/abcore/MainActivity.java index e4d9377a..dafe6fd1 100755 --- a/app/src/main/java/com/greenaddress/abcore/MainActivity.java +++ b/app/src/main/java/com/greenaddress/abcore/MainActivity.java @@ -278,6 +278,10 @@ else if (mDaemonStatus == DaemonStatus.STARTING || mDaemonStatus == DaemonStatus } //for mDaemonStatus = STOPPED we don't have to do anything break; + case "stopped": + mDaemonStatus = DaemonStatus.STOPPED; + mTvStatus.setText(getString(R.string.status_header, mDaemonStatus.toString())); + break; case "localonion": if (mDaemonStatus == DaemonStatus.STARTING || mDaemonStatus == DaemonStatus.UNKNOWN){ mDaemonStatus = DaemonStatus.RUNNING; @@ -318,6 +322,9 @@ else if (mDaemonStatus == DaemonStatus.STOPPED ){ pb.setMax(max); pb.setProgress(percent); textStatus.setText(getString(R.string.progress_bar_message, percent, blocks)); + break; + default: + Log.e(TAG, "Unexpected broadcast result - " + text); } } } diff --git a/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java b/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java index 1f0a9b01..e4dc1b3f 100755 --- a/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java +++ b/app/src/main/java/com/greenaddress/abcore/RPCIntentService.java @@ -155,6 +155,14 @@ private void broadcastError(final Exception e) { sendBroadcast(broadcastIntent); } + private void broadcastStop() { + Log.e(TAG, "broadcastStop"); + final Intent broadcastIntent = new Intent(); + broadcastIntent.setAction(MainActivity.RPCResponseReceiver.ACTION_RESP); + broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); + broadcastIntent.putExtra(PARAM_OUT_MSG, "stopped"); + sendBroadcast(broadcastIntent); + } @Override protected void onHandleIntent(final Intent intent) { @@ -175,6 +183,7 @@ protected void onHandleIntent(final Intent intent) { while (true) { try { getRpc().stop(); + broadcastStop(); break; } catch (final BitcoinRPCException | IOException e) { if (e instanceof BitcoinRPCException && ((BitcoinRPCException) e).getResponse() == null) { @@ -182,6 +191,7 @@ protected void onHandleIntent(final Intent intent) { broadcastError(e); break; } + Log.v(TAG, "stop failed, looping back"); try { Thread.sleep(200); } catch (final InterruptedException e1) {