From 918200378dfb8cfcc923e39a4e2d5f2ce2399e66 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 30 May 2014 18:21:11 +0200 Subject: [PATCH] android: Change how CA certificate reloads are initiated --- .../android/logic/TrustedCertificateManager.java | 16 ++++++++-------- .../android/ui/TrustedCertificatesActivity.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java b/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java index 6e0c9f7a7e..82a7cbe4ea 100644 --- a/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java +++ b/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java @@ -33,6 +33,7 @@ public class TrustedCertificateManager private static final String TAG = TrustedCertificateManager.class.getSimpleName(); private final ReentrantReadWriteLock mLock = new ReentrantReadWriteLock(); private Hashtable mCACerts = new Hashtable(); + private volatile boolean mReload; private boolean mLoaded; private final ArrayList mKeyStores = new ArrayList(); @@ -94,16 +95,14 @@ public class TrustedCertificateManager } /** - * Forces a load/reload of the cached CA certificates. - * As this takes a while it should be called asynchronously. + * Invalidates the current load state so that the next call to load() + * will force a reload of the cached CA certificates. * @return reference to itself */ - public TrustedCertificateManager reload() + public TrustedCertificateManager reset() { - Log.d(TAG, "Force reload of cached CA certificates"); - this.mLock.writeLock().lock(); - loadCertificates(); - this.mLock.writeLock().unlock(); + Log.d(TAG, "Force reload of cached CA certificates on next load"); + this.mReload = true; return this; } @@ -117,8 +116,9 @@ public class TrustedCertificateManager { Log.d(TAG, "Ensure cached CA certificates are loaded"); this.mLock.writeLock().lock(); - if (!this.mLoaded) + if (!this.mLoaded || this.mReload) { + this.mReload = false; loadCertificates(); } this.mLock.writeLock().unlock(); diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java index 03cf84375b..fbdd9af965 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java +++ b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java @@ -179,7 +179,7 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert @Override protected TrustedCertificateManager doInBackground(Void... params) { - return TrustedCertificateManager.getInstance().reload(); + return TrustedCertificateManager.getInstance().reset().load(); } @Override protected void onPostExecute(TrustedCertificateManager result) -- 2.47.2