mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user