Skip to content

Commit

Permalink
Merge branch 'bitmold-bug_tor_wont_stop_with_activeVPN'
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed May 30, 2020
2 parents da5f80d + b2b92d6 commit 1ecca6b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 157 deletions.
53 changes: 22 additions & 31 deletions app/src/main/java/org/torproject/android/OrbotMainActivity.java
Expand Up @@ -30,7 +30,6 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.animation.AccelerateInterpolator;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
Expand Down Expand Up @@ -60,6 +59,7 @@
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.vpn.VpnConstants;
import org.torproject.android.service.vpn.VpnPrefs;
import org.torproject.android.service.vpn.VpnUtils;
import org.torproject.android.settings.Languages;
import org.torproject.android.settings.LocaleHelper;
import org.torproject.android.settings.SettingsPreferences;
Expand Down Expand Up @@ -93,10 +93,8 @@
import static org.torproject.android.service.TorServiceConstants.ACTION_START_VPN;
import static org.torproject.android.service.TorServiceConstants.ACTION_STOP_VPN;
import static org.torproject.android.service.vpn.VpnPrefs.PREFS_KEY_TORIFIED;
import static org.torproject.android.service.vpn.VpnUtils.getSharedPrefs;

public class OrbotMainActivity extends AppCompatActivity
implements OrbotConstants, OnLongClickListener {
public class OrbotMainActivity extends AppCompatActivity implements OrbotConstants {

/* Useful UI bits */
private TextView lblStatus = null; //the main text display widget
Expand Down Expand Up @@ -200,7 +198,7 @@ public void onCreate(Bundle savedInstanceState) {
}

// Resets previous DNS Port to the default.
getSharedPrefs(getApplicationContext()).edit().putInt(VpnPrefs.PREFS_DNS_PORT,
VpnUtils.getSharedPrefs(getApplicationContext()).edit().putInt(VpnPrefs.PREFS_DNS_PORT,
VpnConstants.TOR_DNS_PORT_DEFAULT).apply();

}
Expand All @@ -212,12 +210,12 @@ private void sendIntentToService(final String action) {
}

private void stopTor() {

// requestTorStatus();
if (mBtnVPN.isChecked()) sendIntentToService(ACTION_STOP_VPN);

Intent intent = new Intent(OrbotMainActivity.this, OrbotService.class);
stopService(intent);


}

/**
Expand Down Expand Up @@ -306,7 +304,13 @@ public void onClick(View v) {
lblPorts = findViewById(R.id.lblPorts);

imgStatus = findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this);
imgStatus.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
toggleTor();
return true;
}
});

downloadText = findViewById(R.id.trafficDown);
uploadText = findViewById(R.id.trafficUp);
Expand All @@ -319,14 +323,7 @@ public void onClick(View v) {
mBtnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (torStatus.equals(TorServiceConstants.STATUS_OFF)) {
lblStatus.setText(getString(R.string.status_starting_up));
startTor();
} else {
lblStatus.setText(getString(R.string.status_shutting_down));
stopTor();
}
toggleTor();
}
});

Expand Down Expand Up @@ -364,7 +361,16 @@ public void onClick(View v) {
setCountrySpinner();

mPulsator = findViewById(R.id.pulsator);
}

private void toggleTor() { // UI entry point for (dis)connecting to Tor
if (torStatus.equals(TorServiceConstants.STATUS_OFF)) {
lblStatus.setText(getString(R.string.status_starting_up));
startTor();
} else {
lblStatus.setText(getString(R.string.status_shutting_down));
stopTor();
}
}

private void setCountrySpinner() {
Expand Down Expand Up @@ -831,7 +837,6 @@ public void run() {
sendIntentToService(ACTION_START_VPN);
} else if (request == REQUEST_VPN && response == RESULT_CANCELED) {
mBtnVPN.setChecked(false);
Prefs.putUseVpn(false);
}

IntentResult scanResult = IntentIntegrator.parseActivityResult(request, response, data);
Expand Down Expand Up @@ -1082,20 +1087,6 @@ private boolean isTorServiceRunning() {
return false;
}

public boolean onLongClick(View view) {

if (torStatus.equals(TorServiceConstants.STATUS_OFF)) {
lblStatus.setText(getString(R.string.status_starting_up));
startTor();
} else {
lblStatus.setText(getString(R.string.status_shutting_down));

stopTor();
}

return true;

}

// this is what takes messages or values from the callback threads or other non-mainUI threads
//and passes them back into the main UI thread for display to the user
Expand Down
Expand Up @@ -28,9 +28,7 @@
import android.net.Uri;
import android.net.VpnService;
import android.os.Build;
import android.os.Debug;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.BaseColumns;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
Expand Down Expand Up @@ -1198,20 +1196,16 @@ private int initControlConnection (int maxTries, boolean isReconnect) throws Exc

}

private int getControlPort ()
{
private int getControlPort () {
int result = -1;

try
{
if (fileControlPort.exists())
{
try {
if (fileControlPort.exists()) {
debug("Reading control port config file: " + fileControlPort.getCanonicalPath());
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileControlPort));
String line = bufferedReader.readLine();

if (line != null)
{
if (line != null) {
String[] lineParts = line.split(":");
result = Integer.parseInt(lineParts[1]);
}
Expand All @@ -1222,30 +1216,22 @@ private int getControlPort ()
//store last valid control port
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());
prefs.edit().putInt("controlport", result).commit();

}
else
{
else {
debug("Control Port config file does not yet exist (waiting for tor): " + fileControlPort.getCanonicalPath());

}


}
catch (FileNotFoundException e)
{
catch (FileNotFoundException e) {
debug("unable to get control port; file not found");
}
catch (Exception e)
{
catch (Exception e) {
debug("unable to read control port config file");
}

return result;
}

public void addEventHandler () throws Exception
{
public void addEventHandler () throws Exception {
// We extend NullEventHandler so that we don't need to provide empty
// implementations for all the events we don't care about.
// ...
Expand All @@ -1258,26 +1244,23 @@ public void addEventHandler () throws Exception
conn.setEventHandler(mEventHandler);

logNotice( "SUCCESS added control port event handler");


}

/**
* Returns the port number that the HTTP proxy is running on
*/
public int getHTTPPort() throws RemoteException {
public int getHTTPPort() {
return mPortHTTP;
}


/**
* Returns the port number that the HTTP proxy is running on
*/
public int getSOCKSPort() throws RemoteException {
public int getSOCKSPort() {
return mPortSOCKS;
}


public String getInfo (String key) {
try {
if(conn !=null){
Expand Down

0 comments on commit 1ecca6b

Please sign in to comment.