android: Pass absolute path to the app's data directory via JNI

This commit is contained in:
Tobias Brunner
2017-09-04 10:41:25 +02:00
parent 98ab757284
commit 3fe9a436ee
2 changed files with 11 additions and 6 deletions
@@ -74,6 +74,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
public static final int VPN_STATE_NOTIFICATION_ID = 1;
private String mLogFile;
private String mAppDir;
private VpnProfileDataSource mDataSource;
private Thread mConnectionHandler;
private VpnProfile mCurrentProfile;
@@ -152,6 +153,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
public void onCreate()
{
mLogFile = getFilesDir().getAbsolutePath() + File.separator + LOG_FILE;
mAppDir = getFilesDir().getAbsolutePath();
mDataSource = new VpnProfileDataSource(this);
mDataSource.open();
@@ -244,7 +246,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
addNotification();
BuilderAdapter builder = new BuilderAdapter(mCurrentProfile);
if (initializeCharon(builder, mLogFile, mCurrentProfile.getVpnType().has(VpnTypeFeature.BYOD)))
if (initializeCharon(builder, mLogFile, mAppDir, mCurrentProfile.getVpnType().has(VpnTypeFeature.BYOD)))
{
Log.i(TAG, "charon started");
SettingsWriter writer = new SettingsWriter();
@@ -645,10 +647,11 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
*
* @param builder BuilderAdapter for this connection
* @param logfile absolute path to the logfile
* @param appdir absolute path to the data directory of the app
* @param byod enable BYOD features
* @return TRUE if initialization was successful
*/
public native boolean initializeCharon(BuilderAdapter builder, String logfile, boolean byod);
public native boolean initializeCharon(BuilderAdapter builder, String logfile, String appdir, boolean byod);
/**
* Deinitialize charon, provided by libandroidbridge.so
@@ -515,7 +515,7 @@ static void set_options(char *logfile)
* Initialize the charonservice object
*/
static void charonservice_init(JNIEnv *env, jobject service, jobject builder,
jboolean byod)
char *appdir, jboolean byod)
{
private_charonservice_t *this;
static plugin_feature_t features[] = {
@@ -602,11 +602,11 @@ static void segv_handler(int signal)
* Initialize charon and the libraries via JNI
*/
JNI_METHOD(CharonVpnService, initializeCharon, jboolean,
jobject builder, jstring jlogfile, jboolean byod)
jobject builder, jstring jlogfile, jstring jappdir, jboolean byod)
{
struct sigaction action;
struct utsname utsname;
char *logfile, *plugins;
char *logfile, *appdir, *plugins;
/* logging for library during initialization, as we have no bus yet */
dbg = dbg_android;
@@ -640,7 +640,9 @@ JNI_METHOD(CharonVpnService, initializeCharon, jboolean,
charon->load_loggers(charon);
charonservice_init(env, this, builder, byod);
appdir = androidjni_convert_jstring(env, jappdir);
charonservice_init(env, this, builder, appdir, byod);
free(appdir);
if (uname(&utsname) != 0)
{