/*
- * Copyright (C) 2012-2015 Tobias Brunner
+ * Copyright (C) 2012-2024 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
*
import android.util.Log;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
-import java.util.Observable;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-public class TrustedCertificateManager extends Observable
+public class TrustedCertificateManager
{
private static final String TAG = TrustedCertificateManager.class.getSimpleName();
private final ReentrantReadWriteLock mLock = new ReentrantReadWriteLock();
private volatile boolean mReload;
private boolean mLoaded;
private final ArrayList<KeyStore> mKeyStores = new ArrayList<KeyStore>();
+ private PropertyChangeSupport mObservers = new PropertyChangeSupport(this);
public enum TrustedCertificateSource
{
return Singleton.mInstance;
}
+ /**
+ * Add an observer for changes to the trusted certificate store. There will
+ * be a "storeChanged" property "change" when anything in the store changed.
+ *
+ * @param observer observer to add
+ */
+ public void addObserver(PropertyChangeListener observer)
+ {
+ mObservers.addPropertyChangeListener(observer);
+ }
+
+ /**
+ * Remove an observer for changes to the trusted certificate store.
+ *
+ * @param observer observer to remove
+ */
+ public void deleteObserver(PropertyChangeListener observer)
+ {
+ mObservers.removePropertyChangeListener(observer);
+ }
+
+ /**
+ * Use a fake property with a forced change to notify observers.
+ */
+ private void notifyObservers()
+ {
+ mObservers.firePropertyChange("storeChanged", false, true);
+ }
+
/**
* Invalidates the current load state so that the next call to load()
* will force a reload of the cached CA certificates.
{
Log.d(TAG, "Force reload of cached CA certificates on next load");
this.mReload = true;
- this.setChanged();
this.notifyObservers();
return this;
}
this.mCACerts = certs;
if (!this.mLoaded)
{
- this.setChanged();
this.notifyObservers();
this.mLoaded = true;
}
import org.strongswan.android.security.TrustedCertificateEntry;
import org.strongswan.android.ui.adapter.TrustedCertificateAdapter;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Map.Entry;
-import java.util.Observable;
-import java.util.Observer;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
}
}
- private class TrustedCertificateManagerObserver implements Observer
+ private class TrustedCertificateManagerObserver implements PropertyChangeListener
{
private ForceLoadContentObserver mContentObserver = new ForceLoadContentObserver();
@Override
- public void update(Observable observable, Object data)
+ public void propertyChange(PropertyChangeEvent evt)
{
mContentObserver.onChange(false);
}