Some cleaning

This commit is contained in:
Thomas 2020-12-07 09:04:44 +01:00
parent 555f108853
commit 62467a3fe1
18 changed files with 438 additions and 456 deletions

View File

@ -18,16 +18,16 @@
package org.eu.exodus_privacy.exodusprivacy; package org.eu.exodus_privacy.exodusprivacy;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.SearchView; import android.widget.SearchView;
@ -57,7 +57,6 @@ public class MainActivity extends AppCompatActivity {
private List<Updatable> fragments; private List<Updatable> fragments;
private SearchView searchView; private SearchView searchView;
private Menu toolbarMenu; private Menu toolbarMenu;
private MenuItem settingsMenuItem;
private String packageName; private String packageName;
private MainBinding binding; private MainBinding binding;
private ApplicationListAdapter.OnAppClickListener onAppClickListener; private ApplicationListAdapter.OnAppClickListener onAppClickListener;
@ -67,7 +66,9 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.main); binding = DataBindingUtil.setContentView(this, R.layout.main);
final MainBinding mainBinding = binding; final MainBinding mainBinding = binding;
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(R.string.app_title); getSupportActionBar().setTitle(R.string.app_title);
}
fragments = new ArrayList<>(); fragments = new ArrayList<>();
NetworkListener networkListener = new NetworkListener() { NetworkListener networkListener = new NetworkListener() {
@ -192,12 +193,9 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
settingsMenuItem = menu.findItem(R.id.action_settings); MenuItem settingsMenuItem = menu.findItem(R.id.action_settings);
Updatable fragment = fragments.get(fragments.size() - 1); Updatable fragment = fragments.get(fragments.size() - 1);
if (fragment instanceof ReportFragment) settingsMenuItem.setVisible(fragment instanceof ReportFragment);
settingsMenuItem.setVisible(true);
else
settingsMenuItem.setVisible(false);
return true; return true;
} }

View File

@ -2,7 +2,6 @@ package org.eu.exodus_privacy.exodusprivacy;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.databinding.BaseObservable; import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable; import androidx.databinding.Bindable;
@ -174,5 +173,4 @@ public class ReportViewModel extends BaseObservable {
} }
} }

View File

@ -115,7 +115,10 @@ public class Utils {
} }
} }
builder.append("<li> "); builder.append("<li> ");
int beginIndex = line.indexOf(starter)+starter.length(); int beginIndex = 0;
if (starter != null) {
beginIndex = line.indexOf(starter) + starter.length();
}
line = line.substring(beginIndex); line = line.substring(beginIndex);
closeTags.add("</li>"); closeTags.add("</li>");
} else { } else {
@ -127,7 +130,7 @@ public class Utils {
closeTags.add("</p>"); closeTags.add("</p>");
} }
while (!line.isEmpty()) { while (!line.isEmpty()) {
Pattern pattern = Pattern.compile("^\\[(.+?)(?=\\]\\()\\]\\((http.+?)(?=\\))\\)"); Pattern pattern = Pattern.compile("^\\[(.+?)(?=]\\()]\\((http.+?)(?=\\))\\)");
//Pattern pattern = Pattern.compile("^\\[(.*)\\]\\((http.*)\\)"); //Pattern pattern = Pattern.compile("^\\[(.*)\\]\\((http.*)\\)");
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
if (matcher.find()) { if (matcher.find()) {
@ -147,7 +150,10 @@ public class Utils {
builder.append("\">"); builder.append("\">");
builder.append(matcher.group(1)); builder.append(matcher.group(1));
builder.append("</a>"); builder.append("</a>");
line = line.substring(matcher.group(1).length()); String sub = matcher.group(1);
if (sub != null) {
line = line.substring(sub.length());
}
continue; continue;
} }
pattern = Pattern.compile("^[*_]{2}(.+)[*_]{2}"); pattern = Pattern.compile("^[*_]{2}(.+)[*_]{2}");
@ -156,21 +162,19 @@ public class Utils {
if (line.startsWith("*")) { if (line.startsWith("*")) {
line = line.replaceFirst("\\*\\*", "<b>"); line = line.replaceFirst("\\*\\*", "<b>");
formatStarter.add("**"); formatStarter.add("**");
} } else {
else {
line = line.replaceFirst("__", "<b>"); line = line.replaceFirst("__", "<b>");
formatStarter.add("__"); formatStarter.add("__");
} }
continue; continue;
} }
pattern = Pattern.compile("^[*_]{1}(.+)"); pattern = Pattern.compile("^[*_](.+)");
matcher = pattern.matcher(line); matcher = pattern.matcher(line);
if (matcher.find()) { if (matcher.find()) {
if (line.startsWith("*")) { if (line.startsWith("*")) {
line = line.replaceFirst("\\*", "<i>"); line = line.replaceFirst("\\*", "<i>");
formatStarter.add("*"); formatStarter.add("*");
} } else {
else {
line = line.replaceFirst("_", "<i>"); line = line.replaceFirst("_", "<i>");
formatStarter.add("_"); formatStarter.add("_");
} }

View File

@ -40,19 +40,12 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class ApplicationListAdapter extends RecyclerView.Adapter { public class ApplicationListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<ApplicationViewModel> applicationViewModels; private final OnAppClickListener onAppClickListener;
private OnAppClickListener onAppClickListener;
private Object filter = "";
private AppListFragment.Type filterType = AppListFragment.Type.NAME;
private final int HIDDEN_APP = 0; private final int HIDDEN_APP = 0;
private final int DISPLAYED_APP = 1; private final int DISPLAYED_APP = 1;
private int displayedApp = 0; private final Comparator<ApplicationViewModel> alphaPackageComparator = (app1, app2) -> {
private Comparator<ApplicationViewModel> alphaPackageComparator = new Comparator<ApplicationViewModel>() {
@Override
public int compare(ApplicationViewModel app1, ApplicationViewModel app2) {
if (app1.label != null && app2.label != null) if (app1.label != null && app2.label != null)
return app1.label.toString().compareToIgnoreCase(app2.label.toString()); return app1.label.toString().compareToIgnoreCase(app2.label.toString());
else if (app2.label != null) else if (app2.label != null)
@ -61,10 +54,13 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
return 1; return 1;
else else
return 0; return 0;
}
}; };
private List<ApplicationViewModel> applicationViewModels;
private Object filter = "";
private AppListFragment.Type filterType = AppListFragment.Type.NAME;
private int displayedApp = 0;
public ApplicationListAdapter(Context context, OnAppClickListener listener) { public ApplicationListAdapter(OnAppClickListener listener) {
applicationViewModels = new ArrayList<>(); applicationViewModels = new ArrayList<>();
onAppClickListener = listener; onAppClickListener = listener;
} }
@ -97,7 +93,8 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
onAppClickListener.onAppClick(vm); onAppClickListener.onAppClick(vm);
} }
}); });
}else { } else //noinspection RedundantSuppression
{
//noinspection unused //noinspection unused
final ApplicationEmptyViewHolder holder = (ApplicationEmptyViewHolder) viewHolder; final ApplicationEmptyViewHolder holder = (ApplicationEmptyViewHolder) viewHolder;
//If something should be done for app that are hidden, it's here //If something should be done for app that are hidden, it's here
@ -119,6 +116,44 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
return displayedApp; return displayedApp;
} }
public void filter(AppListFragment.Type type, Object filterObject) {
displayedApp = 0;
if (type.equals(AppListFragment.Type.NAME)) {
filter = filterObject;
filterType = type;
String filterStr = (String) filterObject;
Pattern p = Pattern.compile(Pattern.quote(filterStr.trim()), Pattern.CASE_INSENSITIVE);
for (ApplicationViewModel app : applicationViewModels) {
app.isVisible = p.matcher(app.label).find();
if (app.isVisible)
displayedApp++;
}
} else if (type.equals(AppListFragment.Type.TRACKER)) {
filter = filterObject;
filterType = type;
Long filterLng = (Long) filterObject;
for (ApplicationViewModel app : applicationViewModels) {
app.isVisible = false;
if (app.trackers != null) {
for (Tracker tracker : app.trackers) {
if (tracker.id == filterLng) {
app.isVisible = true;
displayedApp++;
break;
}
}
}
}
}
notifyDataSetChanged();
}
public interface OnAppClickListener {
void onAppClick(ApplicationViewModel vm);
}
static class ApplicationEmptyViewHolder extends RecyclerView.ViewHolder { static class ApplicationEmptyViewHolder extends RecyclerView.ViewHolder {
ApplicationEmptyViewHolder(View itemView) { ApplicationEmptyViewHolder(View itemView) {
super(itemView); super(itemView);
@ -192,42 +227,4 @@ public class ApplicationListAdapter extends RecyclerView.Adapter {
} }
} }
} }
public interface OnAppClickListener {
void onAppClick(ApplicationViewModel vm);
}
public void filter(AppListFragment.Type type, Object filterObject) {
displayedApp = 0;
if (type.equals(AppListFragment.Type.NAME)) {
filter = filterObject;
filterType = type;
String filterStr = (String) filterObject;
Pattern p = Pattern.compile(Pattern.quote(filterStr.trim()), Pattern.CASE_INSENSITIVE);
for (ApplicationViewModel app : applicationViewModels) {
app.isVisible = p.matcher(app.label).find();
if(app.isVisible)
displayedApp++;
}
} else if(type.equals(AppListFragment.Type.TRACKER)) {
filter = filterObject;
filterType = type;
Long filterLng = (Long) filterObject;
for (ApplicationViewModel app : applicationViewModels) {
app.isVisible = false;
if (app.trackers != null) {
for (Tracker tracker : app.trackers) {
if (tracker.id == filterLng) {
app.isVisible = true;
displayedApp++;
break;
}
}
}
}
}
notifyDataSetChanged();
}
} }

View File

@ -50,7 +50,7 @@ public class PermissionListAdapter extends RecyclerView.Adapter<PermissionListAd
} }
class TrackerListViewHolder extends RecyclerView.ViewHolder { static class TrackerListViewHolder extends RecyclerView.ViewHolder {
PermissionItemBinding permissionItemBinding; PermissionItemBinding permissionItemBinding;
@ -64,8 +64,7 @@ public class PermissionListAdapter extends RecyclerView.Adapter<PermissionListAd
if (permission.name != null) { if (permission.name != null) {
permissionItemBinding.permissionShort.setText(permission.name); permissionItemBinding.permissionShort.setText(permission.name);
permissionItemBinding.permissionShort.setVisibility(View.VISIBLE); permissionItemBinding.permissionShort.setVisibility(View.VISIBLE);
} } else
else
permissionItemBinding.permissionShort.setVisibility(View.GONE); permissionItemBinding.permissionShort.setVisibility(View.GONE);
permissionItemBinding.permissionName.setText(permission.fullName.substring(permission.fullName.lastIndexOf(".") + 1)); permissionItemBinding.permissionName.setText(permission.fullName.substring(permission.fullName.lastIndexOf(".") + 1));
@ -77,15 +76,14 @@ public class PermissionListAdapter extends RecyclerView.Adapter<PermissionListAd
else else
permissionItemBinding.dangerous.setVisibility(View.VISIBLE); permissionItemBinding.dangerous.setVisibility(View.VISIBLE);
manageExpanded(permission); manageExpanded(permission);
permissionItemBinding.mainLayout.setOnClickListener((View.OnClickListener) v -> { permissionItemBinding.mainLayout.setOnClickListener(v -> {
if (permission.description != null && permission.description.trim().length() > 0) { if (permission.description != null && permission.description.trim().length() > 0) {
permission.expanded = !permission.expanded; permission.expanded = !permission.expanded;
manageExpanded(permission); manageExpanded(permission);
} }
}); });
} } else {
else {
permissionItemBinding.permissionName.setText(R.string.no_permissions); permissionItemBinding.permissionName.setText(R.string.no_permissions);
permissionItemBinding.arrow.setText(" "); permissionItemBinding.arrow.setText(" ");
permissionItemBinding.permissionShort.setVisibility(View.GONE); permissionItemBinding.permissionShort.setVisibility(View.GONE);

View File

@ -1,7 +1,6 @@
package org.eu.exodus_privacy.exodusprivacy.adapters; package org.eu.exodus_privacy.exodusprivacy.adapters;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -22,9 +21,10 @@ import java.util.Set;
public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.TrackerListViewHolder> { public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.TrackerListViewHolder> {
private final OnTrackerClickListener trackerClickListener;
private final int layout;
private final Comparator<Tracker> alphaTrackerComparator = (track1, track2) -> track1.name.compareToIgnoreCase(track2.name);
private List<Tracker> trackersList; private List<Tracker> trackersList;
private OnTrackerClickListener trackerClickListener;
private int layout;
public TrackerListAdapter(Set<Tracker> trackerList, int resource, OnTrackerClickListener listener) { public TrackerListAdapter(Set<Tracker> trackerList, int resource, OnTrackerClickListener listener) {
setTrackers(trackerList); setTrackers(trackerList);
@ -55,8 +55,6 @@ public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.
return trackersList.size(); return trackersList.size();
} }
private Comparator<Tracker> alphaTrackerComparator = (track1, track2) -> track1.name.compareToIgnoreCase(track2.name);
public void setTrackers(Set<Tracker> trackers) { public void setTrackers(Set<Tracker> trackers) {
if (trackers != null) { if (trackers != null) {
trackersList = new ArrayList<>(trackers); trackersList = new ArrayList<>(trackers);
@ -64,6 +62,10 @@ public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.
} }
} }
public interface OnTrackerClickListener {
void onTrackerClick(long trackerId);
}
class TrackerListViewHolder extends RecyclerView.ViewHolder { class TrackerListViewHolder extends RecyclerView.ViewHolder {
ViewDataBinding viewDataBinding; ViewDataBinding viewDataBinding;
@ -77,20 +79,13 @@ public class TrackerListAdapter extends RecyclerView.Adapter<TrackerListAdapter.
if (viewDataBinding instanceof TrackerItemBinding) { if (viewDataBinding instanceof TrackerItemBinding) {
TrackerItemBinding binding = (TrackerItemBinding) viewDataBinding; TrackerItemBinding binding = (TrackerItemBinding) viewDataBinding;
if (tracker != null) { if (tracker != null) {
binding.trackerName.setText(tracker.name + ""); binding.trackerName.setText(String.format("%s ➤", tracker.name));
binding.getRoot().setOnClickListener(v -> { binding.getRoot().setOnClickListener(v -> trackerClickListener.onTrackerClick(tracker.id));
trackerClickListener.onTrackerClick(tracker.id); } else
});
}
else
binding.trackerName.setText(R.string.no_trackers); binding.trackerName.setText(R.string.no_trackers);
} }
} }
} }
public interface OnTrackerClickListener{
public void onTrackerClick(long trackerId);
}
} }

View File

@ -40,7 +40,7 @@ public class AppListFragment extends Fragment {
//configure list //configure list
applistBinding.appList.setLayoutManager(new LinearLayoutManager(context)); applistBinding.appList.setLayoutManager(new LinearLayoutManager(context));
applistBinding.appList.setVerticalScrollBarEnabled(scrollbarEnabled); applistBinding.appList.setVerticalScrollBarEnabled(scrollbarEnabled);
adapter = new ApplicationListAdapter(context, onAppClickListener); adapter = new ApplicationListAdapter(onAppClickListener);
adapter.displayAppList(applications); adapter.displayAppList(applications);
adapter.filter(filterType, filterObject); adapter.filter(filterType, filterObject);
applistBinding.appList.setAdapter(adapter); applistBinding.appList.setAdapter(adapter);

View File

@ -16,16 +16,11 @@ import java.util.Map;
class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel>> { class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel>> {
interface Listener {
void onAppsComputed(List<ApplicationViewModel> apps);
}
private static final String gStore = "com.android.vending"; private static final String gStore = "com.android.vending";
private static final String fdroid = "ord.fdroid.fdroid"; private static final String fdroid = "ord.fdroid.fdroid";
private final WeakReference<PackageManager> packageManagerRef;
private WeakReference<PackageManager> packageManagerRef; private final WeakReference<DatabaseManager> databaseManagerRef;
private WeakReference<DatabaseManager> databaseManagerRef; private final WeakReference<Listener> listenerRef;
private WeakReference<Listener> listenerRef;
ComputeAppListTask(WeakReference<PackageManager> packageManagerRef, ComputeAppListTask(WeakReference<PackageManager> packageManagerRef,
WeakReference<DatabaseManager> databaseManagerRef, WeakReference<DatabaseManager> databaseManagerRef,
@ -135,4 +130,8 @@ class ComputeAppListTask extends AsyncTask<Void, Void, List<ApplicationViewModel
return result; return result;
} }
interface Listener {
void onAppsComputed(List<ApplicationViewModel> apps);
}
} }

View File

@ -44,6 +44,7 @@ import org.eu.exodus_privacy.exodusprivacy.adapters.PermissionListAdapter;
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter; import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
import org.eu.exodus_privacy.exodusprivacy.databinding.ReportBinding; import org.eu.exodus_privacy.exodusprivacy.databinding.ReportBinding;
import org.eu.exodus_privacy.exodusprivacy.objects.ReportDisplay; import org.eu.exodus_privacy.exodusprivacy.objects.ReportDisplay;
public class ReportFragment extends Fragment implements Updatable { public class ReportFragment extends Fragment implements Updatable {
private PackageManager packageManager; private PackageManager packageManager;
@ -81,7 +82,7 @@ public class ReportFragment extends Fragment implements Updatable {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
reportBinding = DataBindingUtil.inflate(inflater, R.layout.report, container, false); reportBinding = DataBindingUtil.inflate(inflater, R.layout.report, container, false);
onUpdateComplete(); onUpdateComplete();
return reportBinding.getRoot(); return reportBinding.getRoot();

View File

@ -13,6 +13,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -75,7 +76,7 @@ public class TrackerFragment extends Fragment implements ComputeAppListTask.List
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
trackerBinding = DataBindingUtil.inflate(inflater, R.layout.tracker, container, false); trackerBinding = DataBindingUtil.inflate(inflater, R.layout.tracker, container, false);
if (applications == null) if (applications == null)
applications = new ArrayList<>(); applications = new ArrayList<>();
@ -142,7 +143,7 @@ public class TrackerFragment extends Fragment implements ComputeAppListTask.List
else else
trackerBinding.trackerPresenceNb.setBackgroundResource(R.drawable.square_light_blue); trackerBinding.trackerPresenceNb.setBackgroundResource(R.drawable.square_light_blue);
trackerBinding.trackerPresenceNb.setText(percent+"%"); trackerBinding.trackerPresenceNb.setText(String.format("%s%%", percent));
Context context = trackerBinding.getRoot().getContext(); Context context = trackerBinding.getRoot().getContext();
String presence = context.getResources().getString(R.string.tracker_presence, displayedApps); String presence = context.getResources().getString(R.string.tracker_presence, displayedApps);
trackerBinding.trackerPresence.setText(presence); trackerBinding.trackerPresence.setText(presence);

View File

@ -25,6 +25,8 @@ import java.util.EventListener;
*/ */
public interface NetworkListener extends EventListener { public interface NetworkListener extends EventListener {
void onSuccess(); void onSuccess();
void onError(String error); void onError(String error);
void onProgress(int resourceId, int progress, int maxProgress); void onProgress(int resourceId, int progress, int maxProgress);
} }

View File

@ -136,8 +136,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
if (!existTracker(db, tracker.id)) { if (!existTracker(db, tracker.id)) {
values.put("id", tracker.id); values.put("id", tracker.id);
db.insert("trackers", null, values); db.insert("trackers", null, values);
} } else {
else {
String where = "id = ?"; String where = "id = ?";
String[] whereArgs = {String.valueOf(tracker.id)}; String[] whereArgs = {String.valueOf(tracker.id)};
db.update("trackers", values, where, whereArgs); db.update("trackers", values, where, whereArgs);
@ -188,8 +187,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
if (!existReport(db, report.id)) { if (!existReport(db, report.id)) {
values.put("id", report.id); values.put("id", report.id);
db.insert("reports", null, values); db.insert("reports", null, values);
} } else {
else {
String where = "id = ?"; String where = "id = ?";
String[] whereArgs = {String.valueOf(report.id)}; String[] whereArgs = {String.valueOf(report.id)};
db.update("reports", values, where, whereArgs); db.update("reports", values, where, whereArgs);
@ -371,8 +369,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
String[] whereArgs = {String.valueOf(trackerId)}; String[] whereArgs = {String.valueOf(trackerId)};
Cursor cursor = db.query("trackers", null, where, whereArgs, null, null, null, null); Cursor cursor = db.query("trackers", null, where, whereArgs, null, null, null, null);
Tracker tracker = null; Tracker tracker = null;
if(cursor.moveToFirst()) if (cursor.moveToFirst()) {
{
tracker = new Tracker(); tracker = new Tracker();
int col = 0; int col = 0;
tracker.id = cursor.getLong(col++); tracker.id = cursor.getLong(col++);
@ -412,8 +409,7 @@ public class DatabaseManager extends SQLiteOpenHelper {
String[] columns = {"sources"}; String[] columns = {"sources"};
Cursor cursor = getReadableDatabase().query("applications", columns, where, whereArgs, null, null, null, null); Cursor cursor = getReadableDatabase().query("applications", columns, where, whereArgs, null, null, null, null);
String sourcesStr = ""; String sourcesStr = "";
if(cursor.moveToFirst()) if (cursor.moveToFirst()) {
{
sourcesStr = cursor.getString(0); sourcesStr = cursor.getString(0);
} }
cursor.close(); cursor.close();

View File

@ -22,6 +22,12 @@ import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Bundle; import android.os.Bundle;
import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
import org.eu.exodus_privacy.exodusprivacy.objects.Application;
import org.eu.exodus_privacy.exodusprivacy.objects.Report;
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -36,9 +42,7 @@ import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -46,17 +50,9 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
import org.eu.exodus_privacy.exodusprivacy.objects.Application;
import org.eu.exodus_privacy.exodusprivacy.objects.Report;
import org.eu.exodus_privacy.exodusprivacy.objects.Tracker;
/* /*
Singleton that handle all network connection Singleton that handle all network connection
*/ */
@ -84,11 +80,6 @@ public class NetworkManager {
addMessageToQueue(mes); addMessageToQueue(mes);
} }
private enum Message_Type {
GET_REPORTS,
UNKNOWN
}
private void addMessageToQueue(Message mes) { private void addMessageToQueue(Message mes) {
if (thread == null || thread.getState() == Thread.State.TERMINATED || !thread.isRunning) if (thread == null || thread.getState() == Thread.State.TERMINATED || !thread.isRunning)
thread = new NetworkProcessingThread(); thread = new NetworkProcessingThread();
@ -97,11 +88,16 @@ public class NetworkManager {
thread.start(); thread.start();
} }
private enum Message_Type {
GET_REPORTS,
UNKNOWN
}
private class NetworkProcessingThread extends Thread { private class NetworkProcessingThread extends Thread {
private List<Message> messageQueue;
private Semaphore sem;
boolean isRunning;
private final String apiUrl = "https://reports.exodus-privacy.eu.org/api/"; private final String apiUrl = "https://reports.exodus-privacy.eu.org/api/";
private final List<Message> messageQueue;
private final Semaphore sem;
boolean isRunning;
NetworkProcessingThread() { NetworkProcessingThread() {
messageQueue = new ArrayList<>(); messageQueue = new ArrayList<>();
@ -164,8 +160,7 @@ public class NetworkManager {
String jsonStr = getJSON(inStream); String jsonStr = getJSON(inStream);
try { try {
object = new JSONObject(jsonStr); object = new JSONObject(jsonStr);
} catch (Exception e) } catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -196,9 +191,11 @@ public class NetworkManager {
try { try {
JSONObject trackers = object.getJSONObject("trackers"); JSONObject trackers = object.getJSONObject("trackers");
List<Tracker> trackersList = new ArrayList<>(); List<Tracker> trackersList = new ArrayList<>();
for(int i = 0; i<trackers.names().length(); i++) { JSONArray trackerNames = trackers.names();
mes.listener.onProgress(R.string.parse_trackers,i+1,trackers.names().length()); if (trackerNames != null) {
String trackerId = trackers.names().get(i).toString(); for (int i = 0; i < trackerNames.length(); i++) {
mes.listener.onProgress(R.string.parse_trackers, i + 1, trackerNames.length());
String trackerId = trackerNames.get(i).toString();
JSONObject tracker = trackers.getJSONObject(trackerId); JSONObject tracker = trackers.getJSONObject(trackerId);
Tracker track = parseTracker(tracker, trackerId); Tracker track = parseTracker(tracker, trackerId);
trackersList.add(track); trackersList.add(track);
@ -207,6 +204,7 @@ public class NetworkManager {
trackersList.clear(); trackersList.clear();
} }
} }
}
if (!trackersList.isEmpty()) if (!trackersList.isEmpty())
DatabaseManager.getInstance(mes.context).insertOrUpdateTrackers(trackersList); DatabaseManager.getInstance(mes.context).insertOrUpdateTrackers(trackersList);
trackersList.clear(); trackersList.clear();
@ -229,7 +227,6 @@ public class NetworkManager {
mes.listener.onProgress(R.string.get_reports, 0, 0); mes.listener.onProgress(R.string.get_reports, 0, 0);
if (object != null) { if (object != null) {
Map<String, Map<String, String>> handles = new HashMap<>(); Map<String, Map<String, String>> handles = new HashMap<>();
ArrayList<String> packages = mes.args.getStringArrayList("packages"); ArrayList<String> packages = mes.args.getStringArrayList("packages");
@ -407,9 +404,7 @@ public class NetworkManager {
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null) { if (networkInfo != null) {
NetworkInfo.State networkState = networkInfo.getState(); NetworkInfo.State networkState = networkInfo.getState();
if (networkState.equals(NetworkInfo.State.CONNECTED)) { return networkState.equals(NetworkInfo.State.CONNECTED);
return true;
}
} }
return false; return false;
} }

View File

@ -19,7 +19,6 @@
package org.eu.exodus_privacy.exodusprivacy.objects; package org.eu.exodus_privacy.exodusprivacy.objects;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
public class Application { public class Application {

View File

@ -7,7 +7,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo; import android.content.pm.PermissionInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import org.eu.exodus_privacy.exodusprivacy.R; import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel; import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;

View File

@ -9,7 +9,7 @@ buildscript {
google() google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.0' classpath 'com.android.tools.build:gradle:4.1.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Tue Jul 07 01:06:44 CEST 2020 #Mon Dec 07 08:49:24 CET 2020
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip