List of usage examples for android.content Context getDir
public abstract File getDir(String name, @FileMode int mode);
From source file:dev.ukanth.ufirewall.Api.java
private static boolean installBinary(Context ctx, int resId, String filename) { try {//w w w . j av a 2 s . c om File f = new File(ctx.getDir("bin", 0), filename); if (f.exists()) { f.delete(); } copyRawFile(ctx, resId, f, "0755"); return true; } catch (Exception e) { Log.e(TAG, "installBinary failed: " + e.getLocalizedMessage()); return false; } }
From source file:dev.ukanth.ufirewall.Api.java
public static String getBusyBoxPath(Context ctx) { if (G.bb_path().equals("system")) { return "busybox "; } else {/* w w w. j a v a 2 s .c om*/ return ctx.getDir("bin", 0).getAbsolutePath() + "/busybox"; } }
From source file:dev.ukanth.ufirewall.Api.java
static void setIpTablePath(Context ctx, boolean setv6) { boolean builtin; String pref = G.ip_path();/*from ww w . j a va 2 s . c om*/ if (pref.equals("system")) { builtin = false; } else if (pref.equals("builtin")) { builtin = true; } else { // auto setting: // IPv4 iptables on ICS+ devices is mostly sane, so we'll use it by default // IPv6 ip6tables can return the wrong exit status (bug #215) so default to our fixed version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && !setv6) { builtin = false; } else { builtin = true; } } String dir = ""; if (builtin) { dir = ctx.getDir("bin", 0).getAbsolutePath() + "/"; } Api.setv6 = setv6; Api.ipPath = dir + (setv6 ? "ip6tables" : "iptables"); Api.bbPath = getBusyBoxPath(ctx); }
From source file:eu.faircode.netguard.ServiceSinkhole.java
public static void setPcap(boolean enabled, Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int record_size = 64; try {//from w w w . j ava 2 s .c o m 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); }