android: Log retries to the same log file

It's cleared when a new connection is started or there is a manual
retry.
This commit is contained in:
Tobias Brunner
2018-07-03 11:31:39 +02:00
parent 1350ee1ec7
commit fb3772ec95
3 changed files with 13 additions and 1 deletions
@@ -79,6 +79,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
public static final String DISCONNECT_ACTION = "org.strongswan.android.CharonVpnService.DISCONNECT"; public static final String DISCONNECT_ACTION = "org.strongswan.android.CharonVpnService.DISCONNECT";
private static final String NOTIFICATION_CHANNEL = "org.strongswan.android.CharonVpnService.VPN_STATE_NOTIFICATION"; private static final String NOTIFICATION_CHANNEL = "org.strongswan.android.CharonVpnService.VPN_STATE_NOTIFICATION";
public static final String LOG_FILE = "charon.log"; public static final String LOG_FILE = "charon.log";
public static final String KEY_IS_RETRY = "retry";
public static final int VPN_STATE_NOTIFICATION_ID = 1; public static final int VPN_STATE_NOTIFICATION_ID = 1;
private String mLogFile; private String mLogFile;
@@ -137,6 +138,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
if (intent != null) if (intent != null)
{ {
VpnProfile profile = null; VpnProfile profile = null;
boolean retry = false;
if (VPN_SERVICE_ACTION.equals(intent.getAction())) if (VPN_SERVICE_ACTION.equals(intent.getAction()))
{ /* triggered when Always-on VPN is activated */ { /* triggered when Always-on VPN is activated */
@@ -159,12 +161,18 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
String password = bundle.getString(VpnProfileDataSource.KEY_PASSWORD); String password = bundle.getString(VpnProfileDataSource.KEY_PASSWORD);
profile.setPassword(password); profile.setPassword(password);
retry = bundle.getBoolean(CharonVpnService.KEY_IS_RETRY, false);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
pref.edit().putString(Constants.PREF_MRU_VPN_PROFILE, profile.getUUID().toString()) pref.edit().putString(Constants.PREF_MRU_VPN_PROFILE, profile.getUUID().toString())
.apply(); .apply();
} }
} }
} }
if (profile != null && !retry)
{ /* delete the log file if this is not an automatic retry */
deleteFile(LOG_FILE);
}
setNextProfile(profile); setNextProfile(profile);
} }
return START_NOT_STICKY; return START_NOT_STICKY;
@@ -295,6 +295,10 @@ public class VpnStateService extends Service
/* reset if this is a manual retry or a new connection */ /* reset if this is a manual retry or a new connection */
mTimeoutProvider.reset(); mTimeoutProvider.reset();
} }
else
{ /* mark this as an automatic retry */
profileInfo.putBoolean(CharonVpnService.KEY_IS_RETRY, true);
}
intent.putExtras(profileInfo); intent.putExtras(profileInfo);
context.startService(intent); context.startService(intent);
} }
@@ -469,7 +469,7 @@ static void set_options(char *logfile)
lib->settings->set_str(lib->settings, lib->settings->set_str(lib->settings,
"charon.filelog.%s.time_format", "%b %e %T", logfile); "charon.filelog.%s.time_format", "%b %e %T", logfile);
lib->settings->set_bool(lib->settings, lib->settings->set_bool(lib->settings,
"charon.filelog.%s.append", FALSE, logfile); "charon.filelog.%s.append", TRUE, logfile);
lib->settings->set_bool(lib->settings, lib->settings->set_bool(lib->settings,
"charon.filelog.%s.flush_line", TRUE, logfile); "charon.filelog.%s.flush_line", TRUE, logfile);
lib->settings->set_int(lib->settings, lib->settings->set_int(lib->settings,