diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context')
4 files changed, 75 insertions, 117 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 deleted file mode 100644 index 075402d..0000000 --- a/app/src/main/java/org/pacien/tincapp/context/AppInfo.java +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
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/AppInfo.kt b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt new file mode 100644 index 0000000..2eb2aa1 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt | |||
@@ -0,0 +1,32 @@ | |||
1 | package org.pacien.tincapp.context | ||
2 | |||
3 | import android.content.res.Resources | ||
4 | import android.os.Build | ||
5 | import org.pacien.tincapp.BuildConfig | ||
6 | import org.pacien.tincapp.R | ||
7 | |||
8 | /** | ||
9 | * @author pacien | ||
10 | */ | ||
11 | object AppInfo { | ||
12 | |||
13 | fun appVersion(r: Resources): String = r.getString( | ||
14 | R.string.info_version_format, | ||
15 | BuildConfig.VERSION_NAME, | ||
16 | BuildConfig.BUILD_TYPE) | ||
17 | |||
18 | fun androidVersion(r: Resources): String = r.getString( | ||
19 | R.string.info_running_on_format, | ||
20 | Build.VERSION.CODENAME, | ||
21 | Build.VERSION.RELEASE) | ||
22 | |||
23 | fun supportedABIs(r: Resources): String = r.getString( | ||
24 | R.string.info_supported_abis_format, | ||
25 | Build.SUPPORTED_ABIS.joinToString(",")) | ||
26 | |||
27 | fun all(r: Resources): String = listOf( | ||
28 | appVersion(r), | ||
29 | androidVersion(r), | ||
30 | supportedABIs(r)).joinToString("\n") | ||
31 | |||
32 | } | ||
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.java b/app/src/main/java/org/pacien/tincapp/context/AppPaths.java deleted file mode 100644 index d854d4e..0000000 --- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.java +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
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 | } | ||
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt new file mode 100644 index 0000000..21db0a4 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | |||
@@ -0,0 +1,43 @@ | |||
1 | package org.pacien.tincapp.context | ||
2 | |||
3 | import android.content.Context | ||
4 | |||
5 | import java.io.File | ||
6 | |||
7 | /** | ||
8 | * @author pacien | ||
9 | * * | ||
10 | * @implNote Logs and PID files are stored in the cache directory for easy clean up. | ||
11 | */ | ||
12 | object AppPaths { | ||
13 | |||
14 | private val CONFDIR = "conf" | ||
15 | private val LOGDIR = "log" | ||
16 | private val PIDDIR = "pid" | ||
17 | |||
18 | private val TINCD_BIN = "libtincd.so" | ||
19 | private val TINC_BIN = "libtinc.so" | ||
20 | |||
21 | private val LOGFILE_FORMAT = "tinc.%s.log" | ||
22 | private val PIDFILE_FORMAT = "tinc.%s.pid" | ||
23 | |||
24 | private val NET_CONF_FILE = "network.conf" | ||
25 | |||
26 | private fun createDirIfNotExists(basePath: File, newDir: String): File { | ||
27 | val f = File(basePath, newDir) | ||
28 | f.mkdirs() | ||
29 | return f | ||
30 | } | ||
31 | |||
32 | fun confDir(ctx: Context): File = ctx.getDir(CONFDIR, Context.MODE_PRIVATE) | ||
33 | fun confDir(ctx: Context, netName: String): File = File(confDir(ctx), netName) | ||
34 | fun logDir(ctx: Context): File = createDirIfNotExists(ctx.cacheDir, LOGDIR) | ||
35 | fun pidDir(ctx: Context): File = createDirIfNotExists(ctx.cacheDir, PIDDIR) | ||
36 | fun logFile(ctx: Context, netName: String): File = File(logDir(ctx), String.format(LOGFILE_FORMAT, netName)) | ||
37 | fun pidFile(ctx: Context, netName: String): File = File(pidDir(ctx), String.format(PIDFILE_FORMAT, netName)) | ||
38 | fun netConfFile(ctx: Context, netName: String): File = File(confDir(ctx, netName), NET_CONF_FILE) | ||
39 | fun binDir(ctx: Context): File = File(ctx.applicationInfo.nativeLibraryDir) | ||
40 | fun tincd(ctx: Context): File = File(binDir(ctx), TINCD_BIN) | ||
41 | fun tinc(ctx: Context): File = File(binDir(ctx), TINC_BIN) | ||
42 | |||
43 | } | ||