From c4cf845650aee14ef2bca637937f253fc13701b5 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Mon, 14 Jul 2014 13:16:19 -0400 Subject: [PATCH] handle NPE in case service disconnects --- src/org/torproject/android/Orbot.java | 58 ++++++++------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 06ffe576..2c637118 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -1082,22 +1082,25 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic mHandler.sendMessage(msg); } - long[] bws = mService.getBandwidth(); - Message msg = mHandler.obtainMessage(TorServiceConstants.MESSAGE_TRAFFIC_COUNT); - msg.getData().putLong("download", bws[0]); - msg.getData().putLong("upload", bws[1]); - msg.getData().putLong("readTotal", bws[2]); - msg.getData().putLong("writeTotal", bws[3]); - mHandler.sendMessage(msg); - - try { Thread.sleep(1000); } - catch (Exception e){} - + if (mService != null) + { + long[] bws = mService.getBandwidth(); + Message msg = mHandler.obtainMessage(TorServiceConstants.MESSAGE_TRAFFIC_COUNT); + msg.getData().putLong("download", bws[0]); + msg.getData().putLong("upload", bws[1]); + msg.getData().putLong("readTotal", bws[2]); + msg.getData().putLong("writeTotal", bws[3]); + mHandler.sendMessage(msg); + + try { Thread.sleep(1000); } + catch (Exception e){} + } - torStatus = mService.getStatus(); + if (mService != null) + torStatus = mService.getStatus(); } } - catch (RemoteException re) + catch (Exception re) { Log.e(TAG, "error getting service updates",re); } @@ -1230,37 +1233,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic mKeepUpdating = false; mService = null; Log.d(TAG,"service was disconnected"); + } }; - - /* - private void createProgressDialog (String msg) - { - if (progressDialog != null && progressDialog.isShowing()) - { - progressDialog.setMessage(msg); - } - else - { - progressDialog = ProgressDialog.show(Orbot.this, "", msg); - progressDialog.setCancelable(true); - } - } - - private void hideProgressDialog () - { - - if (progressDialog != null && progressDialog.isShowing()) - { - progressDialog.dismiss(); - progressDialog = null; - } - - } - */ - - private void setLocale () {