From d360837d494a86930b8323a99691dc52925eb7ea Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 16 Feb 2018 18:42:02 +0100 Subject: Cosmetic --- .../main/java/org/pacien/tincapp/activities/BaseActivity.kt | 6 ++---- .../java/org/pacien/tincapp/activities/ConfigureActivity.kt | 11 ++++------- app/src/main/java/org/pacien/tincapp/commands/Command.kt | 3 --- app/src/main/java/org/pacien/tincapp/commands/Executor.kt | 2 -- app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 2 -- app/src/main/java/org/pacien/tincapp/commands/TincApp.kt | 2 -- app/src/main/java/org/pacien/tincapp/commands/Tincd.kt | 2 -- app/src/main/java/org/pacien/tincapp/context/App.kt | 8 +------- app/src/main/java/org/pacien/tincapp/context/AppInfo.kt | 2 -- app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | 2 -- app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt | 4 ---- .../main/java/org/pacien/tincapp/data/TincConfiguration.kt | 3 --- .../java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt | 4 ---- app/src/main/java/org/pacien/tincapp/extensions/Android.kt | 2 -- .../java/org/pacien/tincapp/extensions/ApacheConfiguration.kt | 3 --- .../java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt | 2 -- app/src/main/java/org/pacien/tincapp/utils/PemUtils.kt | 2 -- 17 files changed, 7 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index c092111..44f3210 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -18,7 +18,6 @@ import org.pacien.tincapp.context.AppInfo * @author pacien */ abstract class BaseActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.base) @@ -38,7 +37,7 @@ abstract class BaseActivity : AppCompatActivity() { resources.getString(R.string.app_license) + "\n\n" + AppInfo.all()) .setNeutralButton(R.string.action_open_project_website) { _, _ -> App.openURL(resources.getString(R.string.app_website_url)) } - .setPositiveButton(R.string.action_close, App.dismissAction) + .setPositiveButton(R.string.action_close, { _, _ -> Unit }) .show() } @@ -47,6 +46,5 @@ abstract class BaseActivity : AppCompatActivity() { protected fun showProgressDialog(@StringRes msg: Int): ProgressDialog = ProgressDialog.show(this, null, getString(msg), true, false) protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) .setTitle(R.string.title_error).setMessage(msg) - .setPositiveButton(R.string.action_close, App.dismissAction).show() - + .setPositiveButton(R.string.action_close, { _, _ -> Unit }).show() } diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt index ec17c11..a67887c 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt @@ -17,7 +17,6 @@ import kotlinx.android.synthetic.main.page_configure.* import org.pacien.tincapp.R import org.pacien.tincapp.commands.Tinc import org.pacien.tincapp.commands.TincApp -import org.pacien.tincapp.context.App import org.pacien.tincapp.context.AppPaths import org.pacien.tincapp.extensions.Java.exceptionallyAccept @@ -25,7 +24,6 @@ import org.pacien.tincapp.extensions.Java.exceptionallyAccept * @author pacien */ class ConfigureActivity : BaseActivity() { - companion object { val REQUEST_SCAN = 0 val SCAN_PROVIDER = "com.google.zxing.client.android" @@ -55,7 +53,7 @@ class ConfigureActivity : BaseActivity() { .setMessage(R.string.message_no_qr_code_scanner) .setPositiveButton(R.string.action_install) { _, _ -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$SCAN_PROVIDER"))) - }.setNegativeButton(R.string.action_cancel, App.dismissAction).show() + }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show() } } @@ -67,7 +65,7 @@ class ConfigureActivity : BaseActivity() { genDialog.new_net_name.text.toString(), genDialog.new_node_name.text.toString(), genDialog.new_passphrase.text.toString()) - }.setNegativeButton(R.string.action_cancel, App.dismissAction).show() + }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show() } fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { @@ -78,7 +76,7 @@ class ConfigureActivity : BaseActivity() { joinDialog!!.net_name.text.toString(), joinDialog!!.invitation_url.text.toString(), joinDialog!!.join_passphrase.text.toString()) - }.setNegativeButton(R.string.action_cancel, App.dismissAction).show() + }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show() } fun openEncryptDecryptPrivateKeyDialog(@Suppress("UNUSED_PARAMETER") v: View) { @@ -89,7 +87,7 @@ class ConfigureActivity : BaseActivity() { encryptDecryptDialog!!.enc_dec_net_name.text.toString(), encryptDecryptDialog.enc_dec_current_passphrase.text.toString(), encryptDecryptDialog.enc_dec_new_passphrase.text.toString()) - }.setNegativeButton(R.string.action_cancel, App.dismissAction).show() + }.setNegativeButton(R.string.action_cancel, { _, _ -> Unit }).show() } private fun writeContent() { @@ -123,5 +121,4 @@ class ConfigureActivity : BaseActivity() { .exceptionallyAccept { runOnUiThread { showErrorDialog(it.cause!!.localizedMessage) } } } } - } diff --git a/app/src/main/java/org/pacien/tincapp/commands/Command.kt b/app/src/main/java/org/pacien/tincapp/commands/Command.kt index cb95619..ccb5f10 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Command.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Command.kt @@ -6,7 +6,6 @@ import java.util.* * @author pacien */ internal class Command(private val cmd: String) { - private data class Option(val key: String, val value: String?) { fun toCommandLineOption(): String = if (value != null) "--$key=$value" else "--$key" } @@ -25,7 +24,5 @@ internal class Command(private val cmd: String) { } fun asList(): List = listOf(cmd) + opts.map { it.toCommandLineOption() } + args - fun asArray(): Array = this.asList().toTypedArray() - } diff --git a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt index a3b5cea..eb04f6d 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt @@ -12,7 +12,6 @@ import java.io.InputStreamReader * @author pacien */ internal object Executor { - private const val FAILED = -1 class CommandExecutionException(msg: String) : Exception(msg) @@ -56,5 +55,4 @@ internal object Executor { fun runAsyncTask(r: () -> Unit) = CompletableFuture.runAsync(Runnable(r), AsyncTask.THREAD_POOL_EXECUTOR)!! fun supplyAsyncTask(s: () -> U) = CompletableFuture.supplyAsync(Supplier(s), AsyncTask.THREAD_POOL_EXECUTOR)!! - } diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index e0cdb12..556288a 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt @@ -7,7 +7,6 @@ import org.pacien.tincapp.context.AppPaths * @author pacien */ object Tinc { - private fun newCommand(netName: String): Command = Command(AppPaths.tinc().absolutePath) .withOption("config", AppPaths.confDir(netName).absolutePath) @@ -47,5 +46,4 @@ object Tinc { .withOption("config", AppPaths.confDir(netName).absolutePath) .withArguments("join", invitationUrl)) .thenApply { it.joinToString("\n") } - } diff --git a/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt b/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt index 11adb69..e5172c8 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt @@ -14,7 +14,6 @@ import java.io.FileNotFoundException * @author pacien */ object TincApp { - private val SCRIPT_SUFFIXES = listOf("-up", "-down", "-created", "-accepted") private val STATIC_SCRIPTS = listOf("tinc", "host", "subnet", "invitation").flatMap { s -> SCRIPT_SUFFIXES.map { s + it } } @@ -49,5 +48,4 @@ object TincApp { .map { Pair(if (newPassphrase?.isNotEmpty() == true) PemUtils.encrypt(it.first, newPassphrase) else it.first, it.second) } .forEach { PemUtils.write(it.first, it.second.writer()) } } - } diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt index 44fcef5..9950b49 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt @@ -6,7 +6,6 @@ import org.pacien.tincapp.context.AppPaths * @author pacien */ object Tincd { - fun start(netName: String, deviceFd: Int, ed25519PrivateKeyFd: Int? = null, rsaPrivateKeyFd: Int? = null) = Executor.forkExec(Command(AppPaths.tincd().absolutePath) .withOption("no-detach") @@ -17,5 +16,4 @@ object Tincd { .withOption("option", "Device=" + deviceFd) .apply { if (ed25519PrivateKeyFd != null) withOption("option", "Ed25519PrivateKeyFile=/proc/self/fd/$ed25519PrivateKeyFd") } .apply { if (rsaPrivateKeyFd != null) withOption("option", "PrivateKeyFile=/proc/self/fd/$rsaPrivateKeyFd") }) - } diff --git a/app/src/main/java/org/pacien/tincapp/context/App.kt b/app/src/main/java/org/pacien/tincapp/context/App.kt index 0a365d0..9fb910b 100644 --- a/app/src/main/java/org/pacien/tincapp/context/App.kt +++ b/app/src/main/java/org/pacien/tincapp/context/App.kt @@ -13,14 +13,12 @@ import org.pacien.tincapp.R * @author pacien */ class App : Application() { - override fun onCreate() { super.onCreate() appContext = applicationContext } companion object { - private var appContext: Context? = null fun getContext() = appContext!! @@ -30,14 +28,10 @@ class App : Application() { AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Dialog) .setTitle(title).setMessage(msg) .apply { if (manualLink != null) setNeutralButton(R.string.action_open_manual) { _, _ -> openURL(manualLink) } } - .setPositiveButton(R.string.action_close, dismissAction) + .setPositiveButton(R.string.action_close, { _, _ -> Unit }) .create().apply { window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) }.show() fun openURL(url: String) = appContext?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) - - val dismissAction = { _: Any, _: Any -> /* nop */ } - } - } diff --git a/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt index 0f61185..2feca05 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt @@ -8,7 +8,6 @@ import org.pacien.tincapp.R * @author pacien */ object AppInfo { - fun appVersion(): String = App.getResources().getString( R.string.info_version_format, BuildConfig.VERSION_NAME, @@ -27,5 +26,4 @@ object AppInfo { appVersion(), androidVersion(), supportedABIs()).joinToString("\n") - } diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt index 2d5e2e4..9315060 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt @@ -10,7 +10,6 @@ import java.io.FileNotFoundException * @implNote Logs and PID files are stored in the cache directory for easy clean up. */ object AppPaths { - private val TINCD_BIN = "libtincd.so" private val TINC_BIN = "libtinc.so" @@ -46,5 +45,4 @@ object AppPaths { fun tincd() = File(binDir(), TINCD_BIN) fun tinc() = File(binDir(), TINC_BIN) - } diff --git a/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt b/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt index f3a7ea8..510ebc9 100644 --- a/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt +++ b/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt @@ -6,9 +6,7 @@ import org.apache.commons.configuration2.ex.ConversionException * @author pacien */ data class CidrAddress(val address: String, val prefix: Int) { - companion object { - private val SEPARATOR = "/" fun fromSlashSeparated(s: String) = try { @@ -16,9 +14,7 @@ data class CidrAddress(val address: String, val prefix: Int) { } catch (e: Exception) { throw ConversionException(e.message, e) } - } fun toSlashSeparated() = address + SEPARATOR + prefix - } diff --git a/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt index 5a8a254..eb55d2d 100644 --- a/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt @@ -10,7 +10,6 @@ import java.io.File */ data class TincConfiguration(val ed25519PrivateKeyFile: File? = null, val privateKeyFile: File? = null) { - companion object { private val KEY_ED25519_PRIVATE_KEY_FILE = "Ed25519PrivateKeyFile" @@ -20,7 +19,5 @@ data class TincConfiguration(val ed25519PrivateKeyFile: File? = null, fun fromTincConfiguration(c: Configuration) = TincConfiguration( c.getFile(KEY_ED25519_PRIVATE_KEY_FILE), c.getFile(KEY_PRIVATE_KEY_FILE)) - } - } diff --git a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt index 7b699c6..fec9a8e 100644 --- a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt @@ -25,9 +25,7 @@ data class VpnInterfaceConfiguration(val addresses: List = emptyLis val allowBypass: Boolean = false, val blocking: Boolean = false, val mtu: Int? = null) { - companion object { - private val KEY_ADDRESSES = "Address" private val KEY_ROUTES = "Route" private val KEY_DNS_SERVERS = "DNSServer" @@ -63,7 +61,6 @@ data class VpnInterfaceConfiguration(val addresses: List = emptyLis c.getStringList(INVITATION_KEY_ROUTES) .map { it.substringBefore(' ') } .map { CidrAddress.fromSlashSeparated(it) }) - } fun write(f: File) = FileBasedConfigurationBuilder(PropertiesConfiguration::class.java) @@ -74,5 +71,4 @@ data class VpnInterfaceConfiguration(val addresses: List = emptyLis } builder.save() } - } diff --git a/app/src/main/java/org/pacien/tincapp/extensions/Android.kt b/app/src/main/java/org/pacien/tincapp/extensions/Android.kt index 6674cc3..2269736 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/Android.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/Android.kt @@ -9,7 +9,6 @@ import org.pacien.tincapp.context.App * @author pacien */ object Android { - fun ArrayAdapter.setElements(elems: Collection) { setNotifyOnChange(false) clear() @@ -21,5 +20,4 @@ object Android { fun TextView.setText(list: List) { text = if (list.isNotEmpty()) list.joinToString("\n") else App.getContext().getString(R.string.value_none) } - } diff --git a/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt b/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt index 48d1118..969c2c8 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt @@ -8,11 +8,8 @@ import java.io.File * @author pacien */ object ApacheConfiguration { - fun Configuration.getStringList(key: String): List = getList(String::class.java, key, emptyList()) fun Configuration.getCidrList(key: String): List = getStringList(key).map { CidrAddress.fromSlashSeparated(it) } fun Configuration.getIntList(key: String): List = getList(Int::class.java, key, emptyList()) - fun Configuration.getFile(key: String): File? = getString(key)?.let { File(it) } - } diff --git a/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt b/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt index d70fa80..53a0f7a 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt @@ -9,7 +9,6 @@ import org.pacien.tincapp.extensions.Java.applyIgnoringException * @author pacien */ object VpnServiceBuilder { - fun VpnService.Builder.addAddress(cidr: CidrAddress): VpnService.Builder = addAddress(cidr.address, cidr.prefix) fun VpnService.Builder.addRoute(cidr: CidrAddress): VpnService.Builder = addRoute(cidr.address, cidr.prefix) fun VpnService.Builder.allowBypass(allow: Boolean): VpnService.Builder = if (allow) allowBypass() else this @@ -47,5 +46,4 @@ object VpnServiceBuilder { .allowBypass(cfg.allowBypass) .setBlocking(cfg.blocking) .overrideMtu(cfg.mtu) - } diff --git a/app/src/main/java/org/pacien/tincapp/utils/PemUtils.kt b/app/src/main/java/org/pacien/tincapp/utils/PemUtils.kt index 33240f9..b75193d 100644 --- a/app/src/main/java/org/pacien/tincapp/utils/PemUtils.kt +++ b/app/src/main/java/org/pacien/tincapp/utils/PemUtils.kt @@ -16,7 +16,6 @@ import java.io.Writer * @author pacien */ object PemUtils { - private val PROVIDER = org.bouncycastle.jce.provider.BouncyCastleProvider() private val ENCRYPTED_PROC_TYPE_HEADER = PemHeader("Proc-Type", "4,ENCRYPTED") private val DEK_INFO_HEADER_KEY = "DEK-Info" @@ -58,5 +57,4 @@ object PemUtils { } else { obj } - } -- cgit v1.2.3