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