make updateStatus() more closely match the state given from TorService

This aims to make the UI more tighly in sync with the data coming from
TorService.  It is not currently perfect in the UI, but it means that the
UI will represent the status bugs in TorService.  This is important because
that status info is now broadcast to any app that wants it.  So the visible
part of Orbot should show want the apps are seeing to aid debugging.  And
status report bugs should be fixed in TorService so that everyone gets the
correctinfo.
This commit is contained in:
Hans-Christoph Steiner 2015-06-09 16:20:41 -04:00
parent 2f1d52f02d
commit 5c2d4501fa
1 changed files with 64 additions and 82 deletions

View File

@ -99,6 +99,8 @@ public class OrbotMainActivity extends Activity
mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
/* Create the widgets before registering for broadcasts to guarantee
* that the widgets exist when the status updates try to update them */
doLayout(); doLayout();
/* receive the internal status broadcasts, which are separate from the public /* receive the internal status broadcasts, which are separate from the public
@ -1045,40 +1047,29 @@ public class OrbotMainActivity extends Activity
aDialog.setCanceledOnTouchOutside(true); aDialog.setCanceledOnTouchOutside(true);
} }
private void updateStatus (String torServiceMsg) /**
{ * Update the layout_main UI based on the status of {@link TorService}.
* {@code torServiceMsg} must never be {@code null}
//now update the layout_main UI based on the status */
if (imgStatus != null) private void updateStatus(String torServiceMsg) {
{
if (torStatus == TorServiceConstants.STATUS_ON)
{
if (torStatus == TorServiceConstants.STATUS_ON) {
imgStatus.setImageResource(R.drawable.toron); imgStatus.setImageResource(R.drawable.toron);
mBtnBrowser.setEnabled(true); mBtnBrowser.setEnabled(true);
// everything is running, clear the status message
if (lblStatus != null && torServiceMsg != null)
if (torServiceMsg.indexOf('%')!=-1)
lblStatus.setText(torServiceMsg);
else
lblStatus.setText(""); lblStatus.setText("");
boolean showFirstTime = mPrefs.getBoolean("connect_first_time", true); boolean showFirstTime = mPrefs.getBoolean("connect_first_time", true);
if (showFirstTime) if (showFirstTime)
{ {
Editor pEdit = mPrefs.edit(); Editor pEdit = mPrefs.edit();
pEdit.putBoolean("connect_first_time", false); pEdit.putBoolean("connect_first_time", false);
pEdit.commit(); pEdit.commit();
showAlert(getString(R.string.status_activated),
showAlert(getString(R.string.status_activated),getString(R.string.connect_first_time),true); getString(R.string.connect_first_time), true);
} }
if (autoStartFromIntent) if (autoStartFromIntent)
@ -1087,27 +1078,27 @@ public class OrbotMainActivity extends Activity
finish(); finish();
Log.e(TAG, "autoStartFromIntent finish"); Log.e(TAG, "autoStartFromIntent finish");
} }
}
else if (torStatus == TorServiceConstants.STATUS_STARTING) } else if (torStatus == TorServiceConstants.STATUS_STARTING) {
{
imgStatus.setImageResource(R.drawable.torstarting); imgStatus.setImageResource(R.drawable.torstarting);
// only show Tor daemon's percentage complete messages
if (lblStatus != null && torServiceMsg != null)
if (torServiceMsg.indexOf('%') != -1) if (torServiceMsg.indexOf('%') != -1)
lblStatus.setText(torServiceMsg); lblStatus.setText(torServiceMsg);
mBtnBrowser.setEnabled(false);
} else if (torStatus == TorServiceConstants.STATUS_STOPPING) {
imgStatus.setImageResource(R.drawable.torstarting);
lblStatus.setText(torServiceMsg);
mBtnBrowser.setEnabled(false);
} else if (torStatus == TorServiceConstants.STATUS_OFF) {
}
else if (torStatus == TorServiceConstants.STATUS_OFF)
{
imgStatus.setImageResource(R.drawable.toroff); imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(getString(R.string.press_to_start)); lblStatus.setText(getString(R.string.press_to_start));
mBtnBrowser.setEnabled(false); mBtnBrowser.setEnabled(false);
} }
if (torServiceMsg != null && torServiceMsg.length() > 0) if (torServiceMsg != null && torServiceMsg.length() > 0)
@ -1116,17 +1107,12 @@ public class OrbotMainActivity extends Activity
} }
} }
}
// guess what? this start's Tor! actually no it just requests via the local ITorService to the remote TorService instance // guess what? this start's Tor! actually no it just requests via the local ITorService to the remote TorService instance
// to start Tor // to start Tor
private void startTor () throws RemoteException private void startTor () throws RemoteException
{ {
Log.i("OrbotMainActivity", "startTor");
sendIntentToService (TorServiceConstants.CMD_START); sendIntentToService (TorServiceConstants.CMD_START);
torStatus = TorServiceConstants.STATUS_STARTING;
mTxtOrbotLog.setText(""); mTxtOrbotLog.setText("");
@ -1199,11 +1185,7 @@ public class OrbotMainActivity extends Activity
downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(totalRead)); downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(totalRead));
uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite)); uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite));
if (torStatus != TorServiceConstants.STATUS_ON) break;
{
updateStatus("");
}
default: default:
super.handleMessage(msg); super.handleMessage(msg);
} }