From 4ca574b85e9b85d44dc8d151e604ec442688574d Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 22 Jan 2024 00:40:38 +0100 Subject: [PATCH] cleanup code - remove useless comment that just says the obvious thing - use same annotation as super class - remove Scrubber class; that replaces some number in upstream, this is not needed for Delta Chat --- .../securesms/LogViewFragment.java | 7 +- .../thoughtcrime/securesms/util/Scrubber.java | 64 ------------------- 2 files changed, 2 insertions(+), 69 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/util/Scrubber.java diff --git a/src/org/thoughtcrime/securesms/LogViewFragment.java b/src/org/thoughtcrime/securesms/LogViewFragment.java index 9a3d1e11f..1341d8bb7 100644 --- a/src/org/thoughtcrime/securesms/LogViewFragment.java +++ b/src/org/thoughtcrime/securesms/LogViewFragment.java @@ -29,7 +29,6 @@ import android.os.Bundle; import android.os.Environment; import android.os.PowerManager; import android.text.TextUtils; -import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -44,7 +43,6 @@ import com.b44t.messenger.DcContext; import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.Prefs; -import org.thoughtcrime.securesms.util.Scrubber; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -75,12 +73,11 @@ public class LogViewFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_view_log, container, false); } @Override - public void onViewCreated(View view, Bundle savedInstanceState) { + public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); logPreview = (EditText) getView().findViewById(R.id.log_preview); @@ -165,7 +162,7 @@ public class LogViewFragment extends Fragment { if (fragment == null) return null; return "**This log may contain sensitive information. If you want to post it publicly you may examine and edit it beforehand.**\n\n" + - buildDescription(fragment) + "\n" + new Scrubber().scrub(grabLogcat()); + buildDescription(fragment) + "\n" + grabLogcat(); } @Override diff --git a/src/org/thoughtcrime/securesms/util/Scrubber.java b/src/org/thoughtcrime/securesms/util/Scrubber.java deleted file mode 100644 index ce85f1402..000000000 --- a/src/org/thoughtcrime/securesms/util/Scrubber.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2014 Open Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.thoughtcrime.securesms.util; - -import android.util.Log; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Scrub data for possibly sensitive information - */ -public class Scrubber { - private static final String TAG = Scrubber.class.getSimpleName(); - private static final Pattern E164_PATTERN = Pattern.compile("\\+\\d{10,15}"); - - private static final Pattern[] DEFAULTS = new Pattern[] { - E164_PATTERN - }; - - private final Pattern[] patterns; - public Scrubber(Pattern... patterns) { - this.patterns = patterns; - } - - public Scrubber() { - this(DEFAULTS); - } - - public String scrub(final String in) { - Log.d(TAG, "scrubbing input"); - String out = in; - for (Pattern pattern : patterns) { - Matcher matcher = pattern.matcher(out); - while (matcher.find()) { - - StringBuilder builder = new StringBuilder(out.substring(0, matcher.start())); - final String censored = matcher.group().substring(0,1) + - new String(new char[matcher.group().length()-3]).replace("\0", "*") + - matcher.group().substring(matcher.group().length()-2); - builder.append(censored); - builder.append(out.substring(matcher.end())); - Log.i(TAG, "replacing a match on /" + pattern.toString() + "/ => " + censored); - out = builder.toString(); - } - } - return out; - } -}