Fix PCAP dialog shown on resume

This commit is contained in:
emanuele-f 2022-12-27 22:51:49 +01:00
parent 46889738c7
commit 916e5cf89b
2 changed files with 10 additions and 3 deletions

View File

@ -1330,6 +1330,7 @@ public class CaptureService extends VpnService implements Runnable {
private void updateServiceStatus(ServiceStatus cur_status) {
// notify the observers
// NOTE: new subscribers will receive the STOPPED status right after their registration
serviceStatus.postValue(cur_status);
if(cur_status == ServiceStatus.STARTED) {

View File

@ -93,6 +93,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
private NavigationView mNavView;
private CaptureHelper mCapHelper;
// helps detecting duplicate state reporting of STOPPED in MutableLiveData
private boolean mWasStarted = false;
private static final String TAG = "Main";
private static final int POS_STATUS = 0;
@ -158,9 +161,10 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
CaptureService.observeStatus(this, serviceStatus -> {
Log.d(TAG, "Service status: " + serviceStatus.name());
if (serviceStatus == CaptureService.ServiceStatus.STARTED)
if (serviceStatus == CaptureService.ServiceStatus.STARTED) {
appStateRunning();
else /* STOPPED */ {
mWasStarted = true;
} else if(mWasStarted) { /* STARTED -> STOPPED */
// The service may still be active (on premature native termination)
if (CaptureService.isServiceActive())
CaptureService.stopService();
@ -179,7 +183,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
startExportSslkeylogfile();
appStateReady();
}
mWasStarted = false;
} else /* STOPPED -> STOPPED */
appStateReady();
});
}