diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/AppInfo.java | 42 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/AppPaths.java | 75 |
2 files changed, 117 insertions, 0 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppInfo.java b/app/src/main/java/org/pacien/tincapp/context/AppInfo.java new file mode 100644 index 0000000..075402d --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/context/AppInfo.java | |||
@@ -0,0 +1,42 @@ | |||
1 | package org.pacien.tincapp.context; | ||
2 | |||
3 | import android.content.res.Resources; | ||
4 | import android.os.Build; | ||
5 | |||
6 | import com.annimon.stream.Stream; | ||
7 | |||
8 | import org.pacien.tincapp.BuildConfig; | ||
9 | import org.pacien.tincapp.R; | ||
10 | |||
11 | /** | ||
12 | * @author pacien | ||
13 | */ | ||
14 | final public class AppInfo { | ||
15 | |||
16 | private AppInfo() { | ||
17 | // static class | ||
18 | } | ||
19 | |||
20 | static public String appVersion(Resources r) { | ||
21 | return r.getString(R.string.info_version_format, | ||
22 | BuildConfig.VERSION_NAME, | ||
23 | BuildConfig.BUILD_TYPE); | ||
24 | } | ||
25 | |||
26 | static public String androidVersion(Resources r) { | ||
27 | return r.getString(R.string.info_running_on_format, | ||
28 | Build.VERSION.CODENAME, | ||
29 | Build.VERSION.RELEASE); | ||
30 | } | ||
31 | |||
32 | static public String supportedABIs(Resources r) { | ||
33 | return r.getString(R.string.info_supported_abis_format, | ||
34 | Stream.of(Build.SUPPORTED_ABIS).reduce((x, y) -> x + "," + y).get()); | ||
35 | } | ||
36 | |||
37 | static public String all(Resources r) { | ||
38 | return Stream.of(appVersion(r), androidVersion(r), supportedABIs(r)) | ||
39 | .reduce((x, y) -> x + '\n' + y).get(); | ||
40 | } | ||
41 | |||
42 | } | ||
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.java b/app/src/main/java/org/pacien/tincapp/context/AppPaths.java new file mode 100644 index 0000000..d854d4e --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.java | |||
@@ -0,0 +1,75 @@ | |||
1 | package org.pacien.tincapp.context; | ||
2 | |||
3 | import android.content.Context; | ||
4 | |||
5 | import java.io.File; | ||
6 | |||
7 | /** | ||
8 | * @author pacien | ||
9 | * @implNote Logs and PID files are stored in the cache directory for easy clean up. | ||
10 | */ | ||
11 | final public class AppPaths { | ||
12 | |||
13 | private AppPaths() { | ||
14 | // static class | ||
15 | } | ||
16 | |||
17 | static final private String CONFDIR = "conf"; | ||
18 | static final private String LOGDIR = "log"; | ||
19 | static final private String PIDDIR = "pid"; | ||
20 | |||
21 | static final private String TINCD_BIN = "libtincd.so"; | ||
22 | static final private String TINC_BIN = "libtinc.so"; | ||
23 | |||
24 | static final private String LOGFILE_FORMAT = "tinc.%s.log"; | ||
25 | static final private String PIDFILE_FORMAT = "tinc.%s.pid"; | ||
26 | |||
27 | static final private String NET_CONF_FILE = "network.conf"; | ||
28 | |||
29 | static private File createDirIfNotExists(File basePath, String newDir) { | ||
30 | File f = new File(basePath, newDir); | ||
31 | f.mkdirs(); | ||
32 | return f; | ||
33 | } | ||
34 | |||
35 | static public File confDir(Context ctx) { | ||
36 | return ctx.getDir(CONFDIR, Context.MODE_PRIVATE); | ||
37 | } | ||
38 | |||
39 | static public File confDir(Context ctx, String netName) { | ||
40 | return new File(confDir(ctx), netName); | ||
41 | } | ||
42 | |||
43 | static public File logDir(Context ctx) { | ||
44 | return createDirIfNotExists(ctx.getCacheDir(), LOGDIR); | ||
45 | } | ||
46 | |||
47 | static public File pidDir(Context ctx) { | ||
48 | return createDirIfNotExists(ctx.getCacheDir(), PIDDIR); | ||
49 | } | ||
50 | |||
51 | static public File logFile(Context ctx, String netName) { | ||
52 | return new File(logDir(ctx), String.format(LOGFILE_FORMAT, netName)); | ||
53 | } | ||
54 | |||
55 | static public File pidFile(Context ctx, String netName) { | ||
56 | return new File(pidDir(ctx), String.format(PIDFILE_FORMAT, netName)); | ||
57 | } | ||
58 | |||
59 | static public File netConfFile(Context ctx, String netName) { | ||
60 | return new File(confDir(ctx, netName), NET_CONF_FILE); | ||
61 | } | ||
62 | |||
63 | static public File binDir(Context ctx) { | ||
64 | return new File(ctx.getApplicationInfo().nativeLibraryDir); | ||
65 | } | ||
66 | |||
67 | static public File tincd(Context ctx) { | ||
68 | return new File(binDir(ctx), TINCD_BIN); | ||
69 | } | ||
70 | |||
71 | static public File tinc(Context ctx) { | ||
72 | return new File(binDir(ctx), TINC_BIN); | ||
73 | } | ||
74 | |||
75 | } | ||