android: Change how CA certificate reloads are initiated
authorTobias Brunner <tobias@strongswan.org>
Fri, 30 May 2014 16:21:11 +0000 (18:21 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 22 Jul 2014 08:41:50 +0000 (10:41 +0200)
src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java
src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java

index 6e0c9f7..82a7cbe 100644 (file)
@@ -33,6 +33,7 @@ public class TrustedCertificateManager
        private static final String TAG = TrustedCertificateManager.class.getSimpleName();
        private final ReentrantReadWriteLock mLock = new ReentrantReadWriteLock();
        private Hashtable<String, X509Certificate> mCACerts = new Hashtable<String, X509Certificate>();
+       private volatile boolean mReload;
        private boolean mLoaded;
        private final ArrayList<KeyStore> mKeyStores = new ArrayList<KeyStore>();
 
@@ -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();
index 03cf843..fbdd9af 100644 (file)
@@ -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)