diff options
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java | 19 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java | 15 |
2 files changed, 33 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java b/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java index 0fa62285..c7e12491 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java @@ -27,7 +27,11 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getSavedProvider import android.content.IntentFilter; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatDelegate; +import androidx.lifecycle.DefaultLifecycleObserver; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.ProcessLifecycleOwner; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.multidex.MultiDexApplication; @@ -49,7 +53,7 @@ import se.leap.bitmaskclient.tor.TorStatusObservable; * Created by cyberta on 24.10.17. */ -public class BitmaskApp extends MultiDexApplication { +public class BitmaskApp extends MultiDexApplication implements DefaultLifecycleObserver { private final static String TAG = BitmaskApp.class.getSimpleName(); private ProviderObservable providerObservable; @@ -74,6 +78,7 @@ public class BitmaskApp extends MultiDexApplication { providerSetupObservable = ProviderSetupObservable.getInstance(); EipSetupObserver.init(this); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); + ProcessLifecycleOwner.get().getLifecycle().addObserver(this); if (!isCalyxOSWithTetheringSupport(this)) { TetheringStateManager.getInstance().init(this); } @@ -87,4 +92,16 @@ public class BitmaskApp extends MultiDexApplication { LocalBroadcastManager.getInstance(this.getApplicationContext()).registerReceiver(downloadBroadcastReceiver, intentFilter); } } + + @Override + public void onStart(@NonNull LifecycleOwner owner) { + DefaultLifecycleObserver.super.onPause(owner); + EipSetupObserver.setActivityForeground(true); + } + + @Override + public void onStop(@NonNull LifecycleOwner owner) { + DefaultLifecycleObserver.super.onResume(owner); + EipSetupObserver.setActivityForeground(false); + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java index c8b8bea4..ed95b75c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java @@ -38,6 +38,7 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PROFILE; import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE; import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOADED_GEOIP_JSON; +import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOADED_VPN_CERTIFICATE; import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE; import static se.leap.bitmaskclient.providersetup.ProviderAPI.DELAY; import static se.leap.bitmaskclient.providersetup.ProviderAPI.DOWNLOAD_MOTD; @@ -80,6 +81,7 @@ import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.providersetup.ProviderAPI; import se.leap.bitmaskclient.providersetup.ProviderAPICommand; import se.leap.bitmaskclient.providersetup.ProviderSetupObservable; +import se.leap.bitmaskclient.providersetup.activities.SetupActivity; import se.leap.bitmaskclient.tor.TorServiceCommand; import se.leap.bitmaskclient.tor.TorStatusObservable; @@ -96,6 +98,8 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta private String observedProfileFromVpnStatus; AtomicInteger reconnectTry = new AtomicInteger(); AtomicBoolean changingGateway = new AtomicBoolean(false); + + AtomicBoolean activityForeground = new AtomicBoolean(false); AtomicInteger setupNClosestGateway = new AtomicInteger(); private Vector<EipSetupListener> listeners = new Vector<>(); private static EipSetupObserver instance; @@ -127,6 +131,10 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta return instance.setupNClosestGateway.get(); } + public static void setActivityForeground(boolean isForeground) { + instance.activityForeground.set(isForeground); + } + public static synchronized void addListener(EipSetupListener listener) { if (instance.listeners.contains(listener)) { return; @@ -235,6 +243,13 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta break; case PROVIDER_OK: Log.d(TAG, "PROVIDER OK - FETCH SUCCESSFUL"); + //no break, continue with next case + case CORRECTLY_DOWNLOADED_VPN_CERTIFICATE: + if (ProviderSetupObservable.getProgress() > 0 && !activityForeground.get()) { + Intent activityIntent = new Intent(appContext, SetupActivity.class); + activityIntent.setAction(Intent.ACTION_MAIN); + appContext.startActivity(activityIntent); + } break; case TOR_TIMEOUT: case TOR_EXCEPTION: |