From 85a3892d4ecad4aae98f062e824f54e477bf8912 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 1 Jul 2017 15:32:47 +0200 Subject: Remove permission fixing options --- .../org/pacien/tincapp/activities/StartActivity.kt | 7 --- .../org/pacien/tincapp/commands/PermissionFixer.kt | 20 --------- .../tincapp/service/VpnInterfaceConfigurator.kt | 52 ---------------------- 3 files changed, 79 deletions(-) delete mode 100644 app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt delete mode 100644 app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt (limited to 'app/src/main/java/org') diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt index 6d39a9d..71d5403 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt @@ -13,7 +13,6 @@ import android.widget.FrameLayout import kotlinx.android.synthetic.main.base.* import org.pacien.tincapp.R -import org.pacien.tincapp.commands.PermissionFixer import org.pacien.tincapp.context.AppPaths import org.pacien.tincapp.service.TincVpnService @@ -63,7 +62,6 @@ class StartActivity : BaseActivity() { AlertDialog.Builder(this) .setTitle(R.string.title_tinc_config_dir) .setMessage(confDir) - .setNeutralButton(R.string.action_fix_perms) { _, _ -> fixPerms() } .setNegativeButton(R.string.action_copy) { _, _ -> copyIntoClipboard(resources.getString(R.string.title_tinc_config_dir), confDir) } .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } .show() @@ -74,9 +72,4 @@ class StartActivity : BaseActivity() { .putExtra(TincVpnService.INTENT_EXTRA_NET_NAME, netName)) } - private fun fixPerms() { - val ok = PermissionFixer.makePrivateDirsPublic(applicationContext) - notify(if (ok) R.string.message_perms_fixed else R.string.message_perms_fix_failure) - } - } diff --git a/app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt b/app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt deleted file mode 100644 index 493927c..0000000 --- a/app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.pacien.tincapp.commands - -import android.annotation.SuppressLint -import android.content.Context -import org.pacien.tincapp.context.AppPaths -import java.io.File - -/** - * @author pacien - */ -object PermissionFixer { - - @SuppressLint("SetWorldReadable", "SetWorldWritable") - private fun setAllRWXPermissions(f: File): Boolean = - f.setReadable(true, false) && f.setWritable(true, false) && f.setExecutable(true, false) - - fun makePrivateDirsPublic(ctx: Context): Boolean = listOf(AppPaths.confDir(ctx), AppPaths.logDir(ctx), AppPaths.pidDir(ctx)) - .map { setAllRWXPermissions(it) }.all { it } - -} diff --git a/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt b/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt deleted file mode 100644 index 8104940..0000000 --- a/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.pacien.tincapp.service - -import android.net.VpnService -import org.apache.commons.configuration2.Configuration -import org.apache.commons.configuration2.builder.fluent.Configurations -import org.apache.commons.configuration2.ex.ConfigurationException -import java.io.File - -/** - * @author pacien - */ -object VpnInterfaceConfigurator { - - val KEY_ADDRESSES = "Address" - val KEY_ROUTES = "Route" - val KEY_DNS_SERVERS = "DNSServer" - val KEY_SEARCH_DOMAINS = "SearchDomain" - val KEY_ALLOWED_APPLICATIONS = "AllowApplication" - val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" - val KEY_ALLOWED_FAMILIES = "AllowFamily" - val KEY_ALLOW_BYPASS = "AllowBypass" - val KEY_BLOCKING = "Blocking" - val KEY_MTU = "MTU" - - private fun Configuration.getStringList(key: String): List = - getList(String::class.java, key, emptyList()) - - private fun Configuration.getCidrList(key: String): List = - getStringList(key).map { CidrAddress(it) } - - private fun Configuration.getIntList(key: String): List = - getList(Int::class.java, key, emptyList()) - - fun applyConfiguration(net: VpnService.Builder, cfg: Configuration): VpnService.Builder = net - .addAddresses(cfg.getCidrList(KEY_ADDRESSES)) - .addRoutes(cfg.getCidrList(KEY_ROUTES)) - .addDnsServers(cfg.getStringList(KEY_DNS_SERVERS)) - .addSearchDomains(cfg.getStringList(KEY_SEARCH_DOMAINS)) - .addAllowedApplications(cfg.getStringList(KEY_ALLOWED_APPLICATIONS)) - .addDisallowedApplications(cfg.getStringList(KEY_DISALLOWED_APPLICATIONS)) - .allowFamilies(cfg.getIntList(KEY_ALLOWED_FAMILIES)) - .allowBypass(cfg.getBoolean(KEY_ALLOW_BYPASS, false)) - .setBlocking(cfg.getBoolean(KEY_BLOCKING, false)) - .overrideMtu(cfg.getInteger(KEY_MTU, null)) - - fun applyConfiguration(net: VpnService.Builder, cfg: File): VpnService.Builder = try { - applyConfiguration(net, Configurations().properties(cfg)) - } catch (e: ConfigurationException) { - throw IllegalArgumentException(e.message) - } - -} -- cgit v1.2.3