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 e8286faf..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,8 +183,15 @@ 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) { + Log.e(TAG, "daemon not responding, already stopped"); + broadcastError(e); + break; + } + Log.v(TAG, "stop failed, looping back"); try { Thread.sleep(200); } catch (final InterruptedException e1) {