From: Tobias Brunner Date: Fri, 19 Jan 2024 17:29:20 +0000 (+0100) Subject: android: Expose static instance for Application object X-Git-Tag: android-2.5.0^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f04d15dfd60af5a8d73d4f8bc7b1242d444eb61;p=thirdparty%2Fstrongswan.git android: Expose static instance for Application object While it seems to be possible to cast Context.getApplicationContext() to the application class, there really is no documented reason why that should actually be the same object. --- 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 d3805a2844..8d653624e1 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 @@ -49,6 +49,7 @@ public class StrongSwanApplication extends Application implements DefaultLifecyc private static final String TAG = StrongSwanApplication.class.getSimpleName(); private static Context mContext; + private static StrongSwanApplication mInstance; private final ExecutorService mExecutorService = Executors.newFixedThreadPool(4); private final Handler mMainHandler = HandlerCompat.createAsync(Looper.getMainLooper()); @@ -75,6 +76,7 @@ public class StrongSwanApplication extends Application implements DefaultLifecyc { super.onCreate(); StrongSwanApplication.mContext = getApplicationContext(); + StrongSwanApplication.mInstance = this; mManagedConfigurationService = new ManagedConfigurationService(mContext); ProcessLifecycleOwner.get().getLifecycle().addObserver(this); @@ -120,6 +122,16 @@ public class StrongSwanApplication extends Application implements DefaultLifecyc return StrongSwanApplication.mContext; } + /** + * Returns the current application object + * + * @return application + */ + public static StrongSwanApplication getInstance() + { + return StrongSwanApplication.mInstance; + } + /** * Returns a thread pool to run tasks in separate threads *