Prevent crash

This commit is contained in:
M66B 2017-03-20 13:08:36 +01:00
parent 8fa6a39e09
commit 56bcd046e6
1 changed files with 22 additions and 9 deletions

View File

@ -192,16 +192,29 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
private native void jni_done();
public static void setPcap(boolean enabled, Context context) {
File pcap = (enabled ? new File(context.getDir("data", MODE_PRIVATE), "netguard.pcap") : null);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String r = prefs.getString("pcap_record_size", null);
if (TextUtils.isEmpty(r))
r = "64";
String f = prefs.getString("pcap_file_size", null);
if (TextUtils.isEmpty(f))
f = "2";
int record_size = Integer.parseInt(r);
int file_size = Integer.parseInt(f) * 1024 * 1024;
int record_size = 64;
try {
String r = prefs.getString("pcap_record_size", null);
if (TextUtils.isEmpty(r))
r = "64";
record_size = Integer.parseInt(r);
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
int file_size = 2 * 1024 * 1024;
try {
String f = prefs.getString("pcap_file_size", null);
if (TextUtils.isEmpty(f))
f = "2";
file_size = Integer.parseInt(f) * 1024 * 1024;
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
File pcap = (enabled ? new File(context.getDir("data", MODE_PRIVATE), "netguard.pcap") : null);
jni_pcap(pcap == null ? null : pcap.getAbsolutePath(), record_size, file_size);
}