Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev fix service leak fixes #553 #561

Merged
merged 8 commits into from
Dec 22, 2021
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
minSdkVersion 16
applicationId 'org.torproject.android'
targetSdkVersion 29
versionCode 1652200100
versionCode 1652200200

versionName getVersionName()
archivesBaseName = "Orbot-$versionName"
Expand Down
155 changes: 80 additions & 75 deletions app/src/main/java/org/torproject/android/OrbotMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,18 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String status = intent.getStringExtra(TorServiceConstants.EXTRA_STATUS);
if (action == null)
return;

switch (action) {
case TorServiceConstants.LOCAL_ACTION_LOG: {
Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE);
msg.obj = intent.getStringExtra(TorServiceConstants.LOCAL_EXTRA_LOG);
msg.getData().putString("status", intent.getStringExtra(TorServiceConstants.EXTRA_STATUS));

if (!TextUtils.isEmpty(status))
msg.getData().putString("status", status);

mStatusUpdateHandler.sendMessage(msg);

break;
Expand All @@ -173,7 +177,9 @@ public void onReceive(Context context, Intent intent) {
msg.getData().putLong("lastWritten", lastWritten);
msg.getData().putLong("totalWritten", totalWritten);
msg.getData().putLong("totalRead", totalRead);
msg.getData().putString("status", intent.getStringExtra(TorServiceConstants.EXTRA_STATUS));

if (!TextUtils.isEmpty(status))
msg.getData().putString("status", status);

mStatusUpdateHandler.sendMessage(msg);

Expand Down Expand Up @@ -203,7 +209,9 @@ public void onReceive(Context context, Intent intent) {
lastStatusIntent = intent;

Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE);
msg.getData().putString("status", intent.getStringExtra(TorServiceConstants.EXTRA_STATUS));

if (!TextUtils.isEmpty(status))
msg.getData().putString("status", status);

mStatusUpdateHandler.sendMessage(msg);
break;
Expand All @@ -214,6 +222,9 @@ public void onReceive(Context context, Intent intent) {
msg.getData().putInt("socks", intent.getIntExtra(OrbotService.EXTRA_SOCKS_PROXY_PORT, -1));
msg.getData().putInt("http", intent.getIntExtra(OrbotService.EXTRA_HTTP_PROXY_PORT, -1));

if (!TextUtils.isEmpty(status))
msg.getData().putString("status", status);

mStatusUpdateHandler.sendMessage(msg);

break;
Expand Down Expand Up @@ -291,7 +302,7 @@ private void stopTor() {
if (mBtnVPN.isChecked()) sendIntentToService(ACTION_STOP_VPN);
sendIntentToService(ACTION_STOP);
}
else if (torStatus.equals(STATUS_STARTING)) {
else if (torStatus.equals(STATUS_STARTING)||torStatus.equals(STATUS_STOPPING)) {

if (!waitingToStop) {
waitingToStop = true;
Expand Down Expand Up @@ -324,6 +335,7 @@ private void doLayout() {

lblStatus = findViewById(R.id.lblStatus);
lblStatus.setOnClickListener(v -> mDrawer.openDrawer(GravityCompat.END));
lblStatus.setText(String.format("Tor v%s", OrbotService.BINARY_TOR_VERSION));

lblPorts = findViewById(R.id.lblPorts);

Expand Down Expand Up @@ -745,7 +757,7 @@ protected void onResume() {
requestTorStatus();

if (torStatus == null)
updateStatus("", TorServiceConstants.STATUS_STOPPING);
updateStatus("", STATUS_OFF);
else
updateStatus(null, torStatus);

Expand Down Expand Up @@ -807,7 +819,7 @@ private void showAlert(String title, String msg, boolean button) {
* Update the layout_main UI based on the status of {@link OrbotService}.
* {@code torServiceMsg} must never be {@code null}
*/
private synchronized void updateStatus(String torServiceMsg, String newTorStatus) {
private void updateStatus(String torServiceMsg, String newTorStatus) {

if (!TextUtils.isEmpty(torServiceMsg)) {
if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER)) {
Expand All @@ -817,105 +829,98 @@ private synchronized void updateStatus(String torServiceMsg, String newTorStatus
mTxtOrbotLog.append(torServiceMsg + '\n');
}

if (torStatus == null || (newTorStatus != null && newTorStatus.equals(torStatus))) {
torStatus = newTorStatus;
return;
} else {
torStatus = newTorStatus;
}

if (torStatus == null) {
return;
}

switch (torStatus) {
case TorServiceConstants.STATUS_ON:
if (!TextUtils.isEmpty(newTorStatus)) {
if (torStatus == null || (newTorStatus != null && newTorStatus.equals(torStatus))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsequential, but newTorStatus should never be null there because TextUtils.isEmpty returned false

torStatus = newTorStatus;
return;
} else {
torStatus = newTorStatus;
}

imgStatus.setImageResource(R.drawable.toron);

mBtnStart.setText(R.string.menu_stop);
mPulsator.stop();
switch (torStatus) {
case TorServiceConstants.STATUS_ON:

if (Prefs.beSnowflakeProxy())
{
lblStatus.setText(getString(R.string.status_activated)+"\n"
+ getString(R.string.snowflake_proxy_enabled));
imgStatus.setImageResource(R.drawable.toron);

SnowfallView sv = findViewById(R.id.snowflake_view);
sv.setVisibility(View.VISIBLE);
sv.restartFalling();
mBtnStart.setText(R.string.menu_stop);
mPulsator.stop();

}
else
{
lblStatus.setText(getString(R.string.status_activated));
SnowfallView sv = findViewById(R.id.snowflake_view);
sv.setVisibility(View.GONE);
sv.stopFalling();
if (Prefs.beSnowflakeProxy()) {
lblStatus.setText(getString(R.string.status_activated) + "\n"
+ getString(R.string.snowflake_proxy_enabled));

SnowfallView sv = findViewById(R.id.snowflake_view);
sv.setVisibility(View.VISIBLE);
sv.restartFalling();

}
} else {
lblStatus.setText(getString(R.string.status_activated));
SnowfallView sv = findViewById(R.id.snowflake_view);
sv.setVisibility(View.GONE);
sv.stopFalling();
}

// if new onion hostnames are generated, update local DB
sendIntentToService(TorServiceConstants.ACTION_UPDATE_ONION_NAMES);
// if new onion hostnames are generated, update local DB
sendIntentToService(TorServiceConstants.ACTION_UPDATE_ONION_NAMES);


if (autoStartFromIntent) {
autoStartFromIntent = false;
Intent resultIntent = lastStatusIntent;

if (autoStartFromIntent) {
autoStartFromIntent = false;
Intent resultIntent = lastStatusIntent;
if (resultIntent == null)
resultIntent = new Intent(ACTION_START);

if (resultIntent == null)
resultIntent = new Intent(ACTION_START);
resultIntent.putExtra(
TorServiceConstants.EXTRA_STATUS,
torStatus == null ? TorServiceConstants.STATUS_OFF : torStatus
);

resultIntent.putExtra(
TorServiceConstants.EXTRA_STATUS,
torStatus == null ? TorServiceConstants.STATUS_OFF : torStatus
);
setResult(RESULT_OK, resultIntent);

setResult(RESULT_OK, resultIntent);
finish();
}

finish();
}
break;

break;
case TorServiceConstants.STATUS_STARTING:

case TorServiceConstants.STATUS_STARTING:
imgStatus.setImageResource(R.drawable.torstarting);

imgStatus.setImageResource(R.drawable.torstarting);
if (torServiceMsg != null) {
if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_BOOTSTRAPPED))
lblStatus.setText(torServiceMsg);
} else {
lblStatus.setText(getString(R.string.status_starting_up));
}

if (torServiceMsg != null) {
if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_BOOTSTRAPPED))
lblStatus.setText(torServiceMsg);
} else {
lblStatus.setText(getString(R.string.status_starting_up));
}
mBtnStart.setText("...");

mBtnStart.setText("...");
break;

break;
case TorServiceConstants.STATUS_STOPPING:

case TorServiceConstants.STATUS_STOPPING:
if (torServiceMsg != null && torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER))
lblStatus.setText(torServiceMsg);

if (torServiceMsg != null && torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER))
imgStatus.setImageResource(R.drawable.torstarting);
lblStatus.setText(torServiceMsg);

imgStatus.setImageResource(R.drawable.torstarting);
lblStatus.setText(torServiceMsg);

break;
break;

case TorServiceConstants.STATUS_OFF:
case TorServiceConstants.STATUS_OFF:

imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(String.format("Tor v%s", OrbotService.BINARY_TOR_VERSION));
mBtnStart.setText(R.string.menu_start);
mPulsator.start();
resetBandwidthStatTextviews();
imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(String.format("Tor v%s", OrbotService.BINARY_TOR_VERSION));
mBtnStart.setText(R.string.menu_start);
mPulsator.start();
resetBandwidthStatTextviews();

break;
break;


}
}
}

Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ext {
guardian_jtorctl : "0.4.5.7",
ipt_proxy : "1.3.0",
portmapper : "2.0.5",
tor_android : "0.4.6.8"
tor_android : "0.4.6.9"
]

libs = [
Expand Down
Loading