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:
parent
2f1d52f02d
commit
5c2d4501fa
|
@ -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,40 +1047,29 @@ public class OrbotMainActivity extends Activity
|
|||
aDialog.setCanceledOnTouchOutside(true);
|
||||
}
|
||||
|
||||
private void updateStatus (String torServiceMsg)
|
||||
{
|
||||
|
||||
//now update the layout_main UI based on the status
|
||||
if (imgStatus != null)
|
||||
{
|
||||
|
||||
if (torStatus == TorServiceConstants.STATUS_ON)
|
||||
{
|
||||
/**
|
||||
* Update the layout_main UI based on the status of {@link TorService}.
|
||||
* {@code torServiceMsg} must never be {@code null}
|
||||
*/
|
||||
private void updateStatus(String torServiceMsg) {
|
||||
|
||||
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
|
||||
// everything is running, clear the status message
|
||||
lblStatus.setText("");
|
||||
|
||||
boolean showFirstTime = mPrefs.getBoolean("connect_first_time",true);
|
||||
boolean showFirstTime = mPrefs.getBoolean("connect_first_time", true);
|
||||
|
||||
if (showFirstTime)
|
||||
{
|
||||
|
||||
Editor pEdit = mPrefs.edit();
|
||||
|
||||
pEdit.putBoolean("connect_first_time",false);
|
||||
|
||||
pEdit.putBoolean("connect_first_time", false);
|
||||
pEdit.commit();
|
||||
|
||||
showAlert(getString(R.string.status_activated),getString(R.string.connect_first_time),true);
|
||||
|
||||
showAlert(getString(R.string.status_activated),
|
||||
getString(R.string.connect_first_time), true);
|
||||
}
|
||||
|
||||
if (autoStartFromIntent)
|
||||
|
@ -1087,27 +1078,27 @@ public class OrbotMainActivity extends Activity
|
|||
finish();
|
||||
Log.e(TAG, "autoStartFromIntent finish");
|
||||
}
|
||||
}
|
||||
else if (torStatus == TorServiceConstants.STATUS_STARTING)
|
||||
{
|
||||
|
||||
} else if (torStatus == TorServiceConstants.STATUS_STARTING) {
|
||||
|
||||
imgStatus.setImageResource(R.drawable.torstarting);
|
||||
|
||||
|
||||
if (lblStatus != null && torServiceMsg != null)
|
||||
if (torServiceMsg.indexOf('%')!=-1)
|
||||
// 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) {
|
||||
|
||||
}
|
||||
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)
|
||||
|
@ -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
|
||||
// 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue