Skip to content

Commit

Permalink
Merge branch 'bridge_wiz_rotation_fix' of https://github.com/bitmold/…
Browse files Browse the repository at this point in the history
…orbot into bitmold-bridge_wiz_rotation_fix
  • Loading branch information
n8fr8 committed Aug 3, 2020
2 parents 3bcb762 + 76a52f7 commit 3b796cf
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 37 deletions.
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@
android:name=".ui.onboarding.OnboardingActivity"
android:configChanges="orientation|screenSize|screenLayout" />

<activity android:name=".ui.onboarding.BridgeWizardActivity" />
<activity
android:name=".ui.onboarding.BridgeWizardActivity"
android:configChanges="orientation|screenSize" />

<activity
android:name=".ui.onboarding.MoatActivity"
android:windowSoftInputMode="stateHidden" />
Expand Down Expand Up @@ -172,4 +175,4 @@

</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

Expand All @@ -27,14 +28,21 @@

public class BridgeWizardActivity extends AppCompatActivity {

private static int MOAT_REQUEST_CODE = 666;
private static final int MOAT_REQUEST_CODE = 666;
private static final int CUSTOM_BRIDGES_REQUEST_CODE = 1312;

private static TextView mTvStatus;
private static HostTester runningHostTest;

private TextView mTvStatus;
private RadioButton mBtDirect;
private RadioButton mBtObfs4;
private RadioButton mBtMeek;
private RadioButton mBtCustom;

private View mBtnConfgiureCustomBridges;

private static final String BUNDLE_KEY_TV_STATUS_VISIBILITY = "visibility";
private static final String BUNDLE_KEY_TV_STATUS_TEXT = "text";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -49,44 +57,64 @@ protected void onCreate(Bundle savedInstanceState) {
}

mTvStatus = findViewById(R.id.lbl_bridge_test_status);
mTvStatus.setVisibility(View.GONE);
if (savedInstanceState == null) {
mTvStatus.setVisibility(View.GONE);
} else {
mTvStatus.setVisibility(savedInstanceState.getInt(BUNDLE_KEY_TV_STATUS_VISIBILITY, View.GONE));
mTvStatus.setText(savedInstanceState.getString(BUNDLE_KEY_TV_STATUS_TEXT, ""));
}

setTitle(getString(R.string.bridges));

findViewById(R.id.btnMoat).setOnClickListener(v -> startActivityForResult(new Intent(BridgeWizardActivity.this, MoatActivity.class),
MOAT_REQUEST_CODE));
findViewById(R.id.btnMoat).setOnClickListener(v -> {
cancelHostTestIfRunning();
startActivityForResult(new Intent(BridgeWizardActivity.this, MoatActivity.class), MOAT_REQUEST_CODE);
});

mBtDirect = findViewById(R.id.btnBridgesDirect);
mBtDirect.setOnClickListener(v -> {
mBtDirect.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (!isChecked) return;
Prefs.setBridgesList("");
Prefs.putBridgesEnabled(false);
testBridgeConnection();

});

mBtObfs4 = findViewById(R.id.btnBridgesObfs4);
mBtObfs4.setOnClickListener(v -> {
mBtObfs4.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (!isChecked) return;
Prefs.setBridgesList("obfs4");
Prefs.putBridgesEnabled(true);
testBridgeConnection();
});


mBtMeek = findViewById(R.id.btnBridgesMeek);
mBtMeek.setOnClickListener(v -> {
mBtMeek.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (!isChecked) return;
Prefs.setBridgesList("meek");
Prefs.putBridgesEnabled(true);
testBridgeConnection();
});


mBtCustom = findViewById(R.id.btnCustomBridges);
mBtCustom.setOnClickListener(view -> startActivity(new Intent(BridgeWizardActivity.this, CustomBridgesActivity.class)));
mBtCustom.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
cancelHostTestIfRunning();
mTvStatus.setVisibility(View.GONE);
mBtnConfgiureCustomBridges.setVisibility(View.VISIBLE);
} else {
mBtnConfgiureCustomBridges.setVisibility(View.GONE);
}
});

mBtnConfgiureCustomBridges = findViewById(R.id.btnConfigureCustomBridges);
mBtnConfgiureCustomBridges.setOnClickListener(v ->
startActivityForResult(new Intent(BridgeWizardActivity.this, CustomBridgesActivity.class), CUSTOM_BRIDGES_REQUEST_CODE));
}

@Override
protected void onResume() {
super.onResume();

evaluateBridgeListState();
}

Expand Down Expand Up @@ -117,41 +145,45 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
else {
evaluateBridgeListState();
}
}
else {
} else if (requestCode == CUSTOM_BRIDGES_REQUEST_CODE) {
if (noBridgesSet()) mBtDirect.setChecked(true);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}


private void testBridgeConnection() {
cancelHostTestIfRunning();
HostTester hostTester = new HostTester();
if (TextUtils.isEmpty(Prefs.getBridgesList()) || (!Prefs.bridgesEnabled())) {
new HostTester().execute("check.torproject.org", "443");
hostTester.execute("check.torproject.org", "443");
} else if (Prefs.getBridgesList().equals("meek")) {
new HostTester().execute("meek.azureedge.net", "443", "d2cly7j4zqgua7.cloudfront.net", "443");
hostTester.execute("meek.azureedge.net", "443", "d2cly7j4zqgua7.cloudfront.net", "443");
} else if (Prefs.getBridgesList().equals("obfs4")) {
new HostTester().execute("85.17.30.79", "443", "154.35.22.9", "443", "192.99.11.54", "443");
hostTester.execute("85.17.30.79", "443", "154.35.22.9", "443", "192.99.11.54", "443");
} else {
hostTester = null;
mTvStatus.setText("");
}
if (hostTester != null) runningHostTest = hostTester;
}

private class HostTester extends AsyncTask<String, Void, Boolean> {
@Override
protected void onPreExecute() {
// Pre Code
mTvStatus.setVisibility(View.VISIBLE);
mTvStatus.setText(R.string.testing_bridges);
mTvStatus.setText(mBtDirect.isChecked() ? R.string.testing_tor_direct : R.string.testing_bridges);
}

@Override
protected Boolean doInBackground(String... host) {
// Background Code
for (int i = 0; i < host.length; i++) {
if (isCancelled()) return null;
String testHost = host[i];
i++; //move to the port
int testPort = Integer.parseInt(host[i]);

if (isHostReachable(testHost, testPort, 10000)) {
return true;
}
Expand All @@ -163,16 +195,30 @@ protected Boolean doInBackground(String... host) {
@Override
protected void onPostExecute(Boolean result) {
// Post Code
runningHostTest = null;
if (result) {
mTvStatus.setText(R.string.testing_bridges_success);

int stringRes = mBtDirect.isChecked() ? R.string.testing_tor_direct_success : R.string.testing_bridges_success;
mTvStatus.setText(stringRes);
} else {
mTvStatus.setText(R.string.testing_bridges_fail);

}
}
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt(BUNDLE_KEY_TV_STATUS_VISIBILITY, mTvStatus.getVisibility());
savedInstanceState.putString(BUNDLE_KEY_TV_STATUS_TEXT, mTvStatus.getText().toString());
super.onSaveInstanceState(savedInstanceState);
}

@Override
public void onDestroy() {
cancelHostTestIfRunning();
mTvStatus = null;
super.onDestroy();
}

@SuppressWarnings("SameParameterValue")
private static boolean isHostReachable(String serverAddress, int serverTCPport, int timeoutMS) {
boolean connected = false;
Expand All @@ -185,8 +231,7 @@ private static boolean isHostReachable(String serverAddress, int serverTCPport,
connected = true;
socket.close();
}
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}

Expand All @@ -195,18 +240,25 @@ private static boolean isHostReachable(String serverAddress, int serverTCPport,

private void evaluateBridgeListState() {
Log.d(getClass().getSimpleName(), String.format("bridgesEnabled=%b, bridgesList=%s", Prefs.bridgesEnabled(), Prefs.getBridgesList()));

if (!Prefs.bridgesEnabled()) {
if (noBridgesSet()) {
mBtDirect.setChecked(true);
}
else if (Prefs.getBridgesList().equals("meek")) {
} else if (Prefs.getBridgesList().equals("meek")) {
mBtMeek.setChecked(true);
}
else if (Prefs.getBridgesList().equals("obfs4")) {
} else if (Prefs.getBridgesList().equals("obfs4")) {
mBtObfs4.setChecked(true);
}
else {
} else {
mBtCustom.setChecked(true);
}
}

private static void cancelHostTestIfRunning() {
if (runningHostTest != null) {
runningHostTest.cancel(true);
runningHostTest = null;
}
}

private static boolean noBridgesSet() {
return !Prefs.bridgesEnabled() || Prefs.getBridgesList().trim().equals("");
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_custom_bridges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text="@string/get_bridges_email" />
android:text="@string/get_bridges_email_request" />

</LinearLayout>

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/content_bridge_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@

</RadioGroup>

<Button
android:id="@+id/btnConfigureCustomBridges"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text="@string/configure_custom_bridges"
android:visibility="gone" />

<TextView
android:id="@+id/lbl_bridge_test_status"
android:layout_width="match_parent"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<string name="bridge_mode">Request New Bridge</string>

<string name="get_bridges_email">Email</string>
<string name="get_bridges_email_request">Request Bridges via Email</string>
<string name="get_bridges_web">Web</string>

<string name="activate">Activate</string>
Expand Down Expand Up @@ -242,7 +243,9 @@
<string name="pref_disable_ipv4_summary">Tells exits not to connect to IPv4 addresses</string>
<string name="app_shortcuts">Tor-Enabled Apps</string>
<string name="testing_bridges">Testing bridge connection to Tor....</string>
<string name="testing_tor_direct">Testing connection to Tor...</string>
<string name="testing_bridges_success">Success. Bridge configuration is good!</string>
<string name="testing_tor_direct_success">Success. Tor connection is good!</string>
<string name="testing_bridges_fail">FAILED. Try another option</string>
<string name="bridge_direct_connect">Connect directly to Tor (Best)</string>
<string name="bridge_community">Connect through community servers</string>
Expand Down Expand Up @@ -270,7 +273,8 @@
<!-- BridgeWizardActivity -->
<string name="request_bridges_from_torproject">Request Bridges from torproject.org</string>
<string name="custom_bridges">Custom Bridges</string>

<string name="configure_custom_bridges">Configure Custom Bridges</string>

<!-- CustomBridgesActivity -->
<string name="use_custom_bridges">Use Custom Bridges</string>
<string name="in_a_browser">In a browser, visit %s and tap "Get Bridges" > "Just Give Me Bridges!"</string>
Expand Down

0 comments on commit 3b796cf

Please sign in to comment.