summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-08 00:34:55 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-08 00:34:55 -0600
commit08cca563882ff7f743789a99f91afa2e9dbac23d (patch)
treeb448da612fb98151a2fa03a086b7ed065c3f8d74 /app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
parent1f30e133d6995689a89add2d0f87102cadf6938b (diff)
ToolsInstaller: Extract to its own classes
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/activity/SettingsActivity.java')
-rw-r--r--app/src/main/java/com/wireguard/android/activity/SettingsActivity.java72
1 files changed, 0 insertions, 72 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
index 06d40ad5..3eb633ff 100644
--- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
@@ -1,14 +1,10 @@
package com.wireguard.android.activity;
import android.app.Activity;
-import android.content.Context;
-import android.os.AsyncTask;
import android.os.Bundle;
-import android.preference.Preference;
import android.preference.PreferenceFragment;
import com.wireguard.android.R;
-import com.wireguard.android.util.RootShell;
/**
* Interface for changing application-global persistent settings.
@@ -30,74 +26,6 @@ public class SettingsActivity extends Activity {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
- final Preference installTools = findPreference("install_cmd_line_tools");
- installTools.setOnPreferenceClickListener(preference -> {
- new ToolsInstaller(preference).execute();
- return true;
- });
- }
- }
-
- private static final class ToolsInstaller extends AsyncTask<Void, Void, Integer> {
- private static final String[][] LIBRARY_NAMED_EXECUTABLES = {
- {"libwg.so", "wg"},
- {"libwg-quick.so", "wg-quick"}
- };
-
- private final Context context;
- private final Preference preference;
-
- private ToolsInstaller(final Preference preference) {
- context = preference.getContext();
- this.preference = preference;
- preference.setEnabled(false);
- preference.setSummary(context.getString(R.string.install_cmd_line_tools_progress));
- }
-
- @Override
- protected Integer doInBackground(final Void... voids) {
- final String libDir = context.getApplicationInfo().nativeLibraryDir;
- final StringBuilder cmd = new StringBuilder();
-
- cmd.append("set -ex;");
-
- for (final String[] libraryNamedExecutable : LIBRARY_NAMED_EXECUTABLES) {
- final String arg1 = '\'' + libDir + '/' + libraryNamedExecutable[0] + '\'';
- final String arg2 = "'/system/xbin/" + libraryNamedExecutable[1] + '\'';
-
- cmd.append(String.format("cmp -s %s %s && ", arg1, arg2));
- }
- cmd.append("exit 114;");
-
- cmd.append("trap 'mount -o ro,remount /system' EXIT;");
- cmd.append("mount -o rw,remount /system;");
-
- for (final String[] libraryNamedExecutable : LIBRARY_NAMED_EXECUTABLES) {
- final String arg1 = '\'' + libDir + '/' + libraryNamedExecutable[0] + '\'';
- final String arg2 = "'/system/xbin/" + libraryNamedExecutable[1] + '\'';
- cmd.append(String.format("cp %s %s; chmod 755 %s;", arg1, arg2, arg2));
- }
-
- return new RootShell(context).run(null, cmd.toString());
- }
-
- @Override
- protected void onPostExecute(final Integer ret) {
- final String status;
-
- switch (ret) {
- case 0:
- status = context.getString(R.string.install_cmd_line_tools_success);
- break;
- case 114 /* OsConstants.EALREADY */:
- status = context.getString(R.string.install_cmd_line_tools_already);
- break;
- default:
- status = context.getString(R.string.install_cmd_line_tools_failure);
- break;
- }
- preference.setSummary(status);
- preference.setEnabled(true);
}
}
}