Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.button.MaterialButtonToggleGroup;
import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
Expand All @@ -29,10 +30,16 @@ public class SettingsBottomSheet extends BottomSheetDialogFragment {
private static final String PREFS = "camex";
private static final int DEFAULT_PORT = 5800;
private static final String DEFAULT_NAME = "android-client";
// camex defaults (see src/main.c)
private static final int DEFAULT_MTU = 1500;
private static final int DEFAULT_KEEPALIVE = 10;
private static final int DEFAULT_TIMEOUT = 20;

private TextInputEditText hostInput, portInput, nameInput, pskInput;
private TextInputEditText mtuInput, keepaliveInput, timeoutInput;
private TextInputLayout pskLayout;
private SwitchMaterial encryptSwitch;
private MaterialButtonToggleGroup transportGroup;

@Nullable
@Override
Expand All @@ -52,6 +59,10 @@ public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState)
pskInput = v.findViewById(R.id.input_psk);
pskLayout = v.findViewById(R.id.layout_psk);
encryptSwitch = v.findViewById(R.id.switch_encrypt);
transportGroup = v.findViewById(R.id.group_transport);
mtuInput = v.findViewById(R.id.input_mtu);
keepaliveInput = v.findViewById(R.id.input_keepalive);
timeoutInput = v.findViewById(R.id.input_server_timeout);

SharedPreferences prefs = requireContext().getSharedPreferences(PREFS, 0);
hostInput.setText(prefs.getString("server_host", ""));
Expand All @@ -64,6 +75,14 @@ public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState)

encryptSwitch.setOnCheckedChangeListener((b, checked) -> pskLayout.setEnabled(checked));

// Transport: default UDP unless "tcp" was saved.
boolean tcp = "tcp".equals(prefs.getString("transport", "udp"));
transportGroup.check(tcp ? R.id.btn_tcp : R.id.btn_udp);

mtuInput.setText(String.valueOf(prefs.getInt("mtu", DEFAULT_MTU)));
keepaliveInput.setText(String.valueOf(prefs.getInt("keepalive", DEFAULT_KEEPALIVE)));
timeoutInput.setText(String.valueOf(prefs.getInt("server_timeout", DEFAULT_TIMEOUT)));

MaterialButton save = v.findViewById(R.id.btn_save);
save.setOnClickListener(view -> save(prefs));
}
Expand All @@ -90,12 +109,37 @@ private void save(SharedPreferences prefs) {
String name = text(nameInput);
if (TextUtils.isEmpty(name)) name = DEFAULT_NAME;

int mtu = parseInt(mtuInput, DEFAULT_MTU);
if (mtu < 576 || mtu > 9000) {
mtuInput.setError(getString(R.string.err_mtu));
return;
}

int keepalive = parseInt(keepaliveInput, DEFAULT_KEEPALIVE);
if (keepalive < 0 || keepalive > 3600) {
keepaliveInput.setError(getString(R.string.err_keepalive));
return;
}

int timeout = parseInt(timeoutInput, DEFAULT_TIMEOUT);
if (timeout < 5 || timeout > 3600) {
timeoutInput.setError(getString(R.string.err_timeout));
return;
}

String transport =
transportGroup.getCheckedButtonId() == R.id.btn_tcp ? "tcp" : "udp";

prefs.edit()
.putString("server_host", host)
.putInt("server_port", port)
.putString("name", name)
.putString("transport", transport)
.putBoolean("encrypt", encryptSwitch.isChecked())
.putString("psk", text(pskInput))
.putInt("mtu", mtu)
.putInt("keepalive", keepalive)
.putInt("server_timeout", timeout)
.apply();

Toast.makeText(requireContext(), R.string.save, Toast.LENGTH_SHORT).show();
Expand All @@ -105,4 +149,14 @@ private void save(SharedPreferences prefs) {
private static String text(TextInputEditText input) {
return input.getText() == null ? "" : input.getText().toString().trim();
}

private static int parseInt(TextInputEditText input, int fallback) {
String s = text(input);
if (TextUtils.isEmpty(s)) return fallback;
try {
return Integer.parseInt(s);
} catch (NumberFormatException ignored) {
return fallback;
}
}
}
15 changes: 15 additions & 0 deletions android/app/src/main/java/org/openipc/camex/TunnelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
args.add("--name"); args.add(getName());
args.add("--server-host"); args.add(getServerHost());
args.add("--port"); args.add(String.valueOf(getServerPort()));
args.add("--transport"); args.add(getTransport());
args.add("--mtu"); args.add(String.valueOf(getInt("mtu", 1500)));
args.add("--keepalive"); args.add(String.valueOf(getInt("keepalive", 10)));
args.add("--server-timeout");
args.add(String.valueOf(getInt("server_timeout", 20)));
if (getEncrypt()) {
args.add("--encrypt");
String psk = getPsk();
Expand Down Expand Up @@ -112,6 +117,16 @@ private String getName() {
.getString("name", "android-client");
}

private String getTransport() {
// udp (default) or tcp
return getSharedPreferences("camex", MODE_PRIVATE)
.getString("transport", "udp");
}

private int getInt(String key, int def) {
return getSharedPreferences("camex", MODE_PRIVATE).getInt(key, def);
}

private boolean getEncrypt() {
return getSharedPreferences("camex", MODE_PRIVATE)
.getBoolean("encrypt", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#1565C0"
android:fillColor="#4D60D9"
android:pathData="M0,0h108v108H0z" />
</vector>
16 changes: 0 additions & 16 deletions android/app/src/main/res/drawable/ic_launcher_foreground.xml

This file was deleted.

86 changes: 85 additions & 1 deletion android/app/src/main/res/layout/bottom_sheet_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,44 @@
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

<!-- Transport: UDP (default) / TCP -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/transport"
android:textSize="14sp" />

<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/group_transport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:singleSelection="true"
app:selectionRequired="true">

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_udp"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/transport_udp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_tcp"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/transport_tcp" />
</com.google.android.material.button.MaterialButtonToggleGroup>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switch_encrypt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="20dp"
android:text="@string/encrypt" />

<com.google.android.material.textfield.TextInputLayout
Expand All @@ -87,6 +120,57 @@
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

<!-- Advanced tunnel parameters -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/advanced"
android:textSize="16sp"
android:textStyle="bold" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/mtu">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_mtu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/keepalive">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_keepalive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/server_timeout">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_server_timeout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_save"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
</adaptive-icon>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,26 @@
<string name="server_host">Server host</string>
<string name="server_port">Server port</string>
<string name="client_name">Client name</string>
<string name="encrypt">Encrypt traffic</string>

<!-- Transport -->
<string name="transport">Transport</string>
<string name="transport_udp">UDP</string>
<string name="transport_tcp">TCP</string>

<!-- Security -->
<string name="encrypt">Encrypt traffic (ChaCha20-Poly1305)</string>
<string name="psk">Pre-shared key</string>

<!-- Advanced -->
<string name="advanced">Advanced</string>
<string name="mtu">MTU (576–9000)</string>
<string name="keepalive">Keepalive, sec (0 = off)</string>
<string name="server_timeout">Server timeout, sec (5–3600)</string>

<string name="save">Save</string>

<!-- Validation errors -->
<string name="err_mtu">MTU must be 576–9000</string>
<string name="err_keepalive">Keepalive must be 0–3600</string>
<string name="err_timeout">Timeout must be 5–3600</string>
</resources>