TABLES.add(TABLE_VPN_PROFILE);
}
- DatabaseHelper(Context context)
+ public DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
{
mManagedConfigurationService = StrongSwanApplication.getInstance().getManagedConfigurationService();
- vpnProfileSqlDataSource = new VpnProfileSqlDataSource(context);
+ vpnProfileSqlDataSource = new VpnProfileSqlDataSource();
dataSources.add(vpnProfileSqlDataSource);
dataSources.add(new VpnProfileManagedDataSource(context));
package org.strongswan.android.data;
import android.content.ContentValues;
-import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
+import org.strongswan.android.logic.StrongSwanApplication;
+
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class VpnProfileSqlDataSource implements VpnProfileDataSource
{
- private DatabaseHelper mDbHelper;
+ private final DatabaseHelper mDbHelper;
+
private SQLiteDatabase mDatabase;
- private final Context mContext;
/**
* Construct a new VPN profile data source. The context is used to
* open/create the database.
- *
- * @param context context used to access the database
*/
- public VpnProfileSqlDataSource(Context context)
+ public VpnProfileSqlDataSource()
{
- this.mContext = context;
+ mDbHelper = StrongSwanApplication.getInstance().getDatabaseHelper();
}
@Override
public VpnProfileDataSource open() throws SQLException
{
- if (mDbHelper == null)
+ if (mDatabase == null)
{
- mDbHelper = new DatabaseHelper(mContext);
mDatabase = mDbHelper.getWritableDatabase();
}
return this;
@Override
public void close()
{
- if (mDbHelper != null)
+ if (mDatabase != null)
{
- mDbHelper.close();
- mDbHelper = null;
+ mDatabase = null;
}
}
import android.os.Looper;
import android.util.Log;
+import org.strongswan.android.data.DatabaseHelper;
import org.strongswan.android.data.ManagedConfigurationService;
import org.strongswan.android.security.LocalCertificateKeyStoreProvider;
import org.strongswan.android.utils.Constants;
private ManagedConfigurationService mManagedConfigurationService;
+ private DatabaseHelper mDatabaseHelper;
+
private final BroadcastReceiver mRestrictionsReceiver = new BroadcastReceiver()
{
@Override
StrongSwanApplication.mContext = getApplicationContext();
StrongSwanApplication.mInstance = this;
+ mDatabaseHelper = new DatabaseHelper(mContext);
+
mManagedConfigurationService = new ManagedConfigurationService(mContext);
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
return mManagedConfigurationService;
}
+ /**
+ * @return the application's database helper used to access its SQLite database
+ */
+ public DatabaseHelper getDatabaseHelper()
+ {
+ return mDatabaseHelper;
+ }
+
/*
* The libraries are extracted to /data/data/org.strongswan.android/...
* during installation. On newer releases most are loaded in JNI_OnLoad.