From: Tobias Brunner Date: Thu, 3 Apr 2025 13:54:02 +0000 (+0200) Subject: android: Fix starting a managed profile as Always-on VPN X-Git-Tag: android-2.5.5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d87be9b981186cd3dec74990353d2818127c288e;p=thirdparty%2Fstrongswan.git android: Fix starting a managed profile as Always-on VPN The callbacks provided via ProcessLifecycleOwner are only triggered when Activities are started. However, when Android triggers the Always-on VPN it directly starts our VpnService subclass, no Activity. So the configs were not loaded and the VPN couldn't be initiated with a managed profile. This ensures the config is loaded right from the start of the app. And by registering for modifications in onCreate() we can also use the correct config if the app is never started in-between changes to the managed profiles and triggering the Always-on VPN. --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java index 7f73dbfb86..a49e1a2696 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2023 Relution GmbH - * Copyright (C) 2014-2024 Tobias Brunner + * Copyright (C) 2014-2025 Tobias Brunner * * Copyright (C) secunet Security Networks AG * @@ -38,14 +38,10 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import androidx.annotation.NonNull; import androidx.core.os.HandlerCompat; -import androidx.lifecycle.DefaultLifecycleObserver; -import androidx.lifecycle.LifecycleOwner; -import androidx.lifecycle.ProcessLifecycleOwner; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -public class StrongSwanApplication extends Application implements DefaultLifecycleObserver +public class StrongSwanApplication extends Application { private static final String TAG = StrongSwanApplication.class.getSimpleName(); @@ -80,6 +76,7 @@ public class StrongSwanApplication extends Application implements DefaultLifecyc public void onCreate() { super.onCreate(); + StrongSwanApplication.mContext = getApplicationContext(); StrongSwanApplication.mInstance = this; @@ -92,24 +89,12 @@ public class StrongSwanApplication extends Application implements DefaultLifecyc mUserCertificateManager = new ManagedUserCertificateManager(mContext, mManagedConfigurationService, mDatabaseHelper); - ProcessLifecycleOwner.get().getLifecycle().addObserver(this); - } - - @Override - public void onResume(@NonNull LifecycleOwner owner) - { reloadManagedConfigurationAndNotifyListeners(); final IntentFilter restrictionsFilter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED); registerReceiver(mRestrictionsReceiver, restrictionsFilter); } - @Override - public void onPause(@NonNull LifecycleOwner owner) - { - unregisterReceiver(mRestrictionsReceiver); - } - private void reloadManagedConfigurationAndNotifyListeners() { final Set uuids = new HashSet<>(mManagedConfigurationService.getManagedProfiles().keySet());