Check for tracker

This commit is contained in:
Thomas 2020-12-11 11:09:35 +01:00
parent 55303f158e
commit 8e4db1d284
5 changed files with 72 additions and 315 deletions

View File

@ -1,13 +1,19 @@
package org.eu.exodus_privacy.exodusprivacy;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
import org.eu.exodus_privacy.exodusprivacy.databinding.AppCheckActivityBinding;
import org.eu.exodus_privacy.exodusprivacy.fragments.TrackerFragment;
import org.eu.exodus_privacy.exodusprivacy.fragments.Updatable;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
import org.eu.exodus_privacy.exodusprivacy.manager.DatabaseManager;
@ -20,13 +26,24 @@ import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CheckAppActivity extends AppCompatActivity implements NetworkListener {
public class CheckAppActivity extends AppCompatActivity implements NetworkListener, TrackerListAdapter.OnTrackerClickListener {
private static final Pattern fdroidRegex = Pattern.compile("https?://f-droid\\.org/[\\w-]+/packages/([\\w.-]+)");
private static final Pattern googleRegex = Pattern.compile("https?://play\\.google\\.com/store/apps/details\\?id=([\\w.-]+)");
ArrayList<Updatable> fragments;
AppCheckActivityBinding binding;
TrackerListAdapter.OnTrackerClickListener onTrackerClickListener = id -> {
TrackerFragment tracker = TrackerFragment.newInstance(id);
fragments.add(tracker);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right, R.anim.slide_in_left, R.anim.slide_out_left)
.replace(R.id.fragment_container, tracker)
.addToBackStack(null)
.commit();
};
private TrackerListAdapter.OnTrackerClickListener trackerClickListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -48,13 +65,15 @@ public class CheckAppActivity extends AppCompatActivity implements NetworkListen
app_id = matcher.group(1);
}
}
setOnTrackerClickListener(trackerClickListener);
fragments = new ArrayList<>();
NetworkManager.getInstance().getSingleReport(CheckAppActivity.this, this, app_id);
}
}
private void setOnTrackerClickListener(TrackerListAdapter.OnTrackerClickListener listener) {
trackerClickListener = listener;
}
@Override
@ -78,14 +97,24 @@ public class CheckAppActivity extends AppCompatActivity implements NetworkListen
}
applicationViewModel.report = reportToKeep;
applicationViewModel.source = reportToKeep.source;
applicationViewModel.versionCode = (int) reportToKeep.versionCode;
applicationViewModel.versionName = reportToKeep.version;
applicationViewModel.trackers = DatabaseManager.getInstance(CheckAppActivity.this).getTrackers(reportToKeep.trackers);
ReportDisplay reportDisplay = ReportDisplay.buildReportDisplay(CheckAppActivity.this, applicationViewModel, null, null);
ReportViewModel viewModel = new ReportViewModel();
viewModel.setReportDisplay(reportDisplay);
TrackerListAdapter trackerAdapter = new TrackerListAdapter(reportDisplay.trackers, R.layout.tracker_item, onTrackerClickListener);
binding = AppCheckActivityBinding.inflate(getLayoutInflater());
binding.reportUrl.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://" + Utils.getDomain() + "/reports/" + reportDisplay.report.id + "/"));
startActivity(intent);
});
binding.setReportInfo(viewModel);
binding.trackers.setAdapter(trackerAdapter);
binding.trackers.setLayoutManager(new LinearLayoutManager(CheckAppActivity.this));
View viewRoot = binding.getRoot();
setContentView(viewRoot);
});
@ -98,4 +127,9 @@ public class CheckAppActivity extends AppCompatActivity implements NetworkListen
@Override
public void onProgress(int resourceId, int progress, int maxProgress) {
}
@Override
public void onTrackerClick(long trackerId) {
}
}

View File

@ -29,6 +29,10 @@ public class Utils {
public static final String APP_PREFS = "app_prefs";
public static final String LAST_REFRESH = "last_refresh";
public static String getDomain() {
return BuildConfig.FLAVOR.compareTo("exodus") == 0 ? "reports.exodus-privacy.eu.org" : "exodus.phm.education.gouv.fr";
}
@SuppressLint("PackageManagerGetSignatures")
public static String getCertificateSHA1Fingerprint(PackageManager pm, String packageName) {
int flags = PackageManager.GET_SIGNATURES;

View File

@ -38,6 +38,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.ReportViewModel;
import org.eu.exodus_privacy.exodusprivacy.Utils;
import org.eu.exodus_privacy.exodusprivacy.adapters.ApplicationViewModel;
import org.eu.exodus_privacy.exodusprivacy.adapters.PermissionListAdapter;
import org.eu.exodus_privacy.exodusprivacy.adapters.TrackerListAdapter;
@ -143,7 +144,7 @@ public class ReportFragment extends Fragment implements Updatable {
if (reportDisplay.report != null) {
reportBinding.reportUrl.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://reports.exodus-privacy.eu.org/reports/" + reportDisplay.report.id + "/"));
intent.setData(Uri.parse("https://" + Utils.getDomain() + "/reports/" + reportDisplay.report.id + "/"));
startActivity(intent);
});
}

View File

@ -24,7 +24,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import org.eu.exodus_privacy.exodusprivacy.BuildConfig;
import org.eu.exodus_privacy.exodusprivacy.R;
import org.eu.exodus_privacy.exodusprivacy.Utils;
import org.eu.exodus_privacy.exodusprivacy.listener.NetworkListener;
@ -112,7 +111,7 @@ public class NetworkManager {
}
private static class NetworkProcessingThread extends Thread {
private final String domain = BuildConfig.FLAVOR.compareTo("exodus") == 0 ? "reports.exodus-privacy.eu.org" : "exodus.phm.education.gouv.fr";
private final String domain = Utils.getDomain();
private final String apiUrl = "https://" + domain + "/api/";
private final List<Message> messageQueue;
private final Semaphore sem;
@ -146,7 +145,8 @@ public class NetworkManager {
editor.apply();
break;
case GET_SINGLE_REPORT:
Application application = getApplicationsNoActions(mes);
String packageName = mes.args.getString("package");
Application application = getSingleReport(mes, packageName);
mes.listener.onSuccess(application);
break;
default:
@ -246,25 +246,6 @@ public class NetworkManager {
}
private Application getApplicationsNoActions(Message mes) {
URL url;
try {
url = new URL(apiUrl + "applications?option=short");
} catch (Exception e) {
e.printStackTrace();
return null;
}
JSONObject object = makeDataRequest(mes.context, mes.listener, url);
if (object != null) {
String packageName = mes.args.getString("package");
if (packageName == null)
return null;
return getSingleReport(mes, packageName);
}
mes.listener.onSuccess(null);
return null;
}
private void getApplications(Message mes) {
mes.listener.onProgress(R.string.get_reports_connection, 0, 0);

View File

@ -16,22 +16,9 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:padding="10dp"
android:src="@{reportInfo.logo}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
@ -44,7 +31,7 @@
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/logo" />
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/dummy"
@ -84,37 +71,7 @@
app:layout_constraintStart_toEndOf="@id/trackers_nb"
app:layout_constraintTop_toTopOf="@id/trackers_nb" />
<TextView
android:id="@+id/permissions_nb"
android:layout_width="40dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:background="@{ContextCompat.getDrawable(context,reportInfo.permissionColor)}"
android:text="@{reportInfo.permissionNumberStr}"
android:textAlignment="center"
android:textColor="@color/textColorWhite"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/trackers_nb" />
<TextView
android:id="@+id/permissions_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
android:text="@string/permissions"
android:textColor="@color/textColorDark"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/permissions_nb"
app:layout_constraintTop_toBottomOf="@id/trackers_nb" />
<TextView
android:id="@+id/installed_version"
@ -123,98 +80,26 @@
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:text="@string/installed"
android:text="@string/report_version"
android:textColor="@color/textColorDark"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/permissions_nb" />
app:layout_constraintTop_toBottomOf="@id/trackers_title" />
<TextView
android:id="@+id/installed_version_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:text="@{reportInfo.installedVersion}"
android:textColor="@color/textColorDark"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/installed_version"
app:layout_constraintTop_toBottomOf="@id/permissions_nb" />
app:layout_constraintTop_toTopOf="@+id/installed_version" />
<TextView
android:id="@+id/report_version"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:text="@string/report_version"
android:textColor="@color/textColorDark"
android:textSize="16sp"
android:visibility="@{reportInfo.reportVersionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/installed_version_value" />
<TextView
android:id="@+id/report_version_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:text="@{reportInfo.reportVersion}"
android:textColor="@color/textColorDark"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="@{reportInfo.reportVersionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/report_version"
app:layout_constraintTop_toBottomOf="@id/installed_version_value" />
<TextView
android:id="@+id/source"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:text="@{reportInfo.source}"
android:textColor="@color/textColorDark"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/report_version_value" />
<TextView
android:id="@+id/creator"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:text="@string/created_by"
android:textColor="@color/textColorDark"
android:textSize="16sp"
android:visibility="@{reportInfo.creatorVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/source" />
<TextView
android:id="@+id/creator_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:textColor="@color/textColorDark"
android:textSize="16sp"
android:visibility="@{reportInfo.creatorVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/creator"
app:layout_constraintTop_toBottomOf="@id/source" />
<TextView
android:id="@+id/report_date"
@ -228,7 +113,7 @@
android:visibility="@{reportInfo.reportVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/creator_value" />
app:layout_constraintTop_toBottomOf="@id/installed_version_value" />
<TextView
android:id="@+id/report_url"
@ -246,179 +131,31 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/report_date" />
<TextView
android:id="@+id/view_store"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:autoLink="web"
android:text="@{reportInfo.viewOnStore}"
android:textAlignment="textEnd"
android:textColor="@color/colorPurple"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/report_url" />
<TextView
android:id="@+id/trackers_nb_list"
android:layout_width="40dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:background="@{ContextCompat.getDrawable(context,reportInfo.trackerColor)}"
android:text="@{reportInfo.trackerNumberStr}"
android:textAlignment="center"
android:textColor="@color/textColorWhite"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="@{reportInfo.trackerVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/analysed" />
<TextView
android:id="@+id/trackers_title_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:text="@string/trackers"
android:textColor="@color/textColorDark"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="@{reportInfo.trackerVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/trackers_nb_list"
app:layout_constraintTop_toBottomOf="@id/analysed" />
<TextView
android:id="@+id/code_signature"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="5dp"
android:visibility="@{reportInfo.trackerVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/trackers_nb_list" />
app:layout_constraintTop_toBottomOf="@id/report_url">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/trackers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="5dp"
android:visibility="@{reportInfo.trackerVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/code_signature" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/trackers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="5dp"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tracker_explanation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="5dp"
android:text="@string/tracker_infos"
android:visibility="@{reportInfo.trackerVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/trackers" />
<TextView
android:id="@+id/permissions_nb_list"
android:layout_width="40dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:background="@{ContextCompat.getDrawable(context,reportInfo.permissionColor)}"
android:text="@{reportInfo.permissionNumberStr}"
android:textAlignment="center"
android:textColor="@color/textColorWhite"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tracker_explanation" />
<TextView
android:id="@+id/permissions_title_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:text="@string/permissions"
android:textColor="@color/textColorDark"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/permissions_nb_list"
app:layout_constraintTop_toBottomOf="@id/tracker_explanation" />
<TextView
android:id="@+id/code_permission"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="5dp"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/permissions_nb_list" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/permissions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="5dp"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toTopOf="@id/permission_explanation_dangerous"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/code_permission" />
<TextView
android:id="@+id/permission_explanation_dangerous"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
android:text="@string/permission_infos_dangerous"
android:visibility="@{reportInfo.hasPermissionDangerous ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toTopOf="@id/permission_explanation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/permission_explanation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
android:text="@string/permission_infos"
android:visibility="@{reportInfo.permissionVisibility ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<RelativeLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
@ -434,7 +171,7 @@
android:visibility="@{reportInfo.trackerVisibility ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_store" />
app:layout_constraintTop_toBottomOf="@id/report_url" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>