Skip to content
Open
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
4 changes: 2 additions & 2 deletions app/src/main/java/io/netbird/client/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ public void deselectRoute(String route) throws Exception {
}

@Override
public String debugBundle(boolean anonymize) throws Exception {
public String debugBundle(boolean anonymize, String anonymizeLevel) throws Exception {
if (mBinder == null) {
throw new Exception("VPN service not connected");
}
return mBinder.debugBundle(anonymize);
return mBinder.debugBundle(anonymize, anonymizeLevel);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/netbird/client/ServiceAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface ServiceAccessor {
void addRouteChangeListener(RouteChangeListener listener);
void removeRouteChangeListener(RouteChangeListener listener);

String debugBundle(boolean anonymize) throws Exception;
String debugBundle(boolean anonymize, String anonymizeLevel) throws Exception;

/** SSO session deadline as unix seconds; 0 when unknown or not bound. */
long sessionExpiresAt();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package io.netbird.client.ui.troubleshoot;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import io.netbird.client.databinding.SheetAnonymizeLevelBinding;
import io.netbird.client.tool.Preferences;

public class AnonymizeLevelSheet extends BottomSheetDialogFragment {

public interface OnLevelChangedListener {
void onAnonymizeLevelChanged(String level);
}

private static final String ARG_LEVEL = "level";

private SheetAnonymizeLevelBinding binding;

public static AnonymizeLevelSheet newInstance(String current) {
AnonymizeLevelSheet sheet = new AnonymizeLevelSheet();
Bundle args = new Bundle();
args.putString(ARG_LEVEL, current);
sheet.setArguments(args);
return sheet;
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = SheetAnonymizeLevelBinding.inflate(inflater, container, false);

binding.levelRowNone.setOnClickListener(v -> pick(Preferences.ANONYMIZE_LEVEL_NONE));
binding.levelRowDefault.setOnClickListener(v -> pick(Preferences.ANONYMIZE_LEVEL_DEFAULT));
binding.levelRowStrict.setOnClickListener(v -> pick(Preferences.ANONYMIZE_LEVEL_STRICT));

showCheckmarkFor(currentLevel());
return binding.getRoot();
}

@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}

private String currentLevel() {
Bundle args = getArguments();
if (args == null) {
return Preferences.ANONYMIZE_LEVEL_DEFAULT;
}
return args.getString(ARG_LEVEL, Preferences.ANONYMIZE_LEVEL_DEFAULT);
}

private void showCheckmarkFor(String level) {
binding.levelCheckNone.setVisibility(
Preferences.ANONYMIZE_LEVEL_NONE.equals(level) ? View.VISIBLE : View.INVISIBLE);
binding.levelCheckStrict.setVisibility(
Preferences.ANONYMIZE_LEVEL_STRICT.equals(level) ? View.VISIBLE : View.INVISIBLE);
binding.levelCheckDefault.setVisibility(
Preferences.ANONYMIZE_LEVEL_NONE.equals(level) || Preferences.ANONYMIZE_LEVEL_STRICT.equals(level)
? View.INVISIBLE : View.VISIBLE);
}

private void pick(String level) {
if (getParentFragment() instanceof OnLevelChangedListener) {
((OnLevelChangedListener) getParentFragment()).onAnonymizeLevelChanged(level);
}
dismiss();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
import io.netbird.client.tool.Preferences;
import io.netbird.client.tool.ProfileManagerWrapper;

public class TroubleshootFragment extends Fragment {
public class TroubleshootFragment extends Fragment implements AnonymizeLevelSheet.OnLevelChangedListener {

private static final String LOGTAG = "TroubleshootFragment";

private FragmentTroubleshootBinding binding;
private Preferences preferences;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentTroubleshootBinding.inflate(inflater, container, false);

Preferences preferences = new Preferences(inflater.getContext());
preferences = new Preferences(inflater.getContext());
binding.switchTraceLog.setChecked(preferences.isTraceLogEnabled());

binding.switchTraceLog.setOnCheckedChangeListener((buttonView, isChecked) -> {
Expand All @@ -44,9 +46,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
binding.switchTraceLog.toggle();
});

binding.anonymizeLayout.setOnClickListener(v -> {
binding.switchAnonymize.toggle();
});
updateAnonymizeValue();
binding.anonymizeLayout.setOnClickListener(v ->
AnonymizeLevelSheet.newInstance(preferences.getAnonymizeLevel())
.show(getChildFragmentManager(), "anonymize_level"));

initializeRemoteJobsSwitch(inflater.getContext());

Expand All @@ -63,6 +66,18 @@ public void onDestroyView() {
binding = null;
}

@Override
public void onAnonymizeLevelChanged(String level) {
preferences.setAnonymizeLevel(level);
if (binding != null) {
updateAnonymizeValue();
}
}

private void updateAnonymizeValue() {
binding.anonymizeValue.setText(anonymizeLevelLabel(preferences.getAnonymizeLevel()));
}

private void initializeRemoteJobsSwitch(Context context) {
try {
String configFilePath = new ProfileManagerWrapper(context).getActiveConfigPath();
Expand All @@ -88,11 +103,15 @@ private void generateDebugBundle() {
return;
}

boolean anonymize = binding.switchAnonymize.isChecked();
String level = preferences.getAnonymizeLevel();
boolean anonymize = !Preferences.ANONYMIZE_LEVEL_NONE.equals(level);
String anonymizeLevel = Preferences.ANONYMIZE_LEVEL_STRICT.equals(level)
? Preferences.ANONYMIZE_LEVEL_STRICT
: Preferences.ANONYMIZE_LEVEL_DEFAULT;
binding.buttonDebugBundle.setEnabled(false);
new Thread(() -> {
try {
String key = ((ServiceAccessor) activity).debugBundle(anonymize);
String key = ((ServiceAccessor) activity).debugBundle(anonymize, anonymizeLevel);
activity.runOnUiThread(() -> {
if (binding == null || !isAdded()) return;
binding.buttonDebugBundle.setEnabled(true);
Expand All @@ -111,4 +130,15 @@ private void generateDebugBundle() {
}
}).start();
}

private static int anonymizeLevelLabel(String level) {
switch (level) {
case Preferences.ANONYMIZE_LEVEL_NONE:
return R.string.troubleshoot_anonymize_none;
case Preferences.ANONYMIZE_LEVEL_STRICT:
return R.string.troubleshoot_anonymize_strict;
default:
return R.string.troubleshoot_anonymize_default;
}
}
}
56 changes: 35 additions & 21 deletions app/src/main/res/layout/fragment_troubleshoot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<include layout="@layout/list_item_setting_divider" />

<LinearLayout
android:id="@+id/anonymize_layout"
android:id="@+id/allow_remote_jobs_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/settings_row_bg"
Expand All @@ -64,30 +64,49 @@
android:minHeight="56dp"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="16dp">
android:paddingEnd="16dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">

<TextView
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/troubleshoot_anonymize"
android:textColor="@color/nb_txt"
android:textSize="16sp" />
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/troubleshoot_allow_remote_jobs"
android:textColor="@color/nb_txt"
android:textSize="16sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="@string/troubleshoot_allow_remote_jobs_desc"
android:textColor="@color/nb_txt_light"
android:textSize="12sp" />
</LinearLayout>

<com.google.android.material.switchmaterial.SwitchMaterial
style="@style/Widget.NetBird.Switch"
android:id="@+id/switch_anonymize"
android:id="@+id/switch_allow_remote_jobs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:clickable="false"
android:focusable="false" />
</LinearLayout>

<include layout="@layout/list_item_setting_divider" />
<!-- Section: Debug bundle -->
<TextView
style="@style/SettingsSectionHeader"
android:text="@string/troubleshoot_section_debug_bundle" />

<LinearLayout
android:id="@+id/allow_remote_jobs_layout"
android:id="@+id/anonymize_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/settings_row_bg"
Expand All @@ -110,34 +129,29 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/troubleshoot_allow_remote_jobs"
android:text="@string/troubleshoot_anonymize"
android:textColor="@color/nb_txt"
android:textSize="16sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="@string/troubleshoot_allow_remote_jobs_desc"
android:text="@string/troubleshoot_anonymize_desc"
android:textColor="@color/nb_txt_light"
android:textSize="12sp" />
</LinearLayout>

<com.google.android.material.switchmaterial.SwitchMaterial
style="@style/Widget.NetBird.Switch"
android:id="@+id/switch_allow_remote_jobs"
<TextView
android:id="@+id/anonymize_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:clickable="false"
android:focusable="false" />
android:textColor="@color/nb_txt_light"
android:textSize="14sp"
tools:text="@string/troubleshoot_anonymize_default" />
</LinearLayout>

<!-- Section: Debug bundle -->
<TextView
style="@style/SettingsSectionHeader"
android:text="@string/troubleshoot_section_debug_bundle" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Loading
Loading