handle NPE in case service disconnects

This commit is contained in:
Nathan Freitas 2014-07-14 13:16:19 -04:00
parent 1e6ff3579b
commit c4cf845650
1 changed files with 17 additions and 41 deletions

View File

@ -1082,22 +1082,25 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
} }
long[] bws = mService.getBandwidth(); if (mService != null)
Message msg = mHandler.obtainMessage(TorServiceConstants.MESSAGE_TRAFFIC_COUNT); {
msg.getData().putLong("download", bws[0]); long[] bws = mService.getBandwidth();
msg.getData().putLong("upload", bws[1]); Message msg = mHandler.obtainMessage(TorServiceConstants.MESSAGE_TRAFFIC_COUNT);
msg.getData().putLong("readTotal", bws[2]); msg.getData().putLong("download", bws[0]);
msg.getData().putLong("writeTotal", bws[3]); msg.getData().putLong("upload", bws[1]);
mHandler.sendMessage(msg); msg.getData().putLong("readTotal", bws[2]);
msg.getData().putLong("writeTotal", bws[3]);
mHandler.sendMessage(msg);
try { Thread.sleep(1000); } try { Thread.sleep(1000); }
catch (Exception e){} catch (Exception e){}
}
if (mService != null)
torStatus = mService.getStatus(); torStatus = mService.getStatus();
} }
} }
catch (RemoteException re) catch (Exception re)
{ {
Log.e(TAG, "error getting service updates",re); Log.e(TAG, "error getting service updates",re);
} }
@ -1230,37 +1233,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
mKeepUpdating = false; mKeepUpdating = false;
mService = null; mService = null;
Log.d(TAG,"service was disconnected"); 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 () private void setLocale ()
{ {