Skip to content

Commit ea32fbe

Browse files
author
Konrad Kollnig
committed
Improve app-wise internet blocking
1 parent 19f6ad4 commit ea32fbe

File tree

8 files changed

+42
-80
lines changed

8 files changed

+42
-80
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId = "net.kollnig.missioncontrol"
99
minSdkVersion 22
1010
targetSdkVersion 29
11-
versionCode 2020060801
12-
versionName "2020.06.08"
11+
versionCode 2020070701
12+
versionName "2020.07.07"
1313
archivesBaseName = "TrackerControl-$versionName" // name of apk
1414

1515
externalNativeBuild {

app/src/main/java/net/kollnig/missioncontrol/details/TrackersFragment.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
package net.kollnig.missioncontrol.details;
1919

2020
import android.content.Context;
21-
import android.content.Intent;
2221
import android.os.AsyncTask;
2322
import android.os.Bundle;
2423
import android.view.LayoutInflater;
2524
import android.view.View;
2625
import android.view.ViewGroup;
27-
import android.widget.Button;
2826

2927
import androidx.fragment.app.Fragment;
3028
import androidx.recyclerview.widget.LinearLayoutManager;
@@ -53,8 +51,6 @@ public class TrackersFragment extends Fragment {
5351
private TrackersListAdapter adapter;
5452

5553
private RecyclerView recyclerView;
56-
private View emptyView;
57-
private Button btnLaunch;
5854

5955
private boolean running = false;
6056

@@ -95,28 +91,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
9591
trackerList = TrackerList.getInstance(context);
9692
recyclerView = v.findViewById(R.id.transmissions_list);
9793
recyclerView.setLayoutManager(new LinearLayoutManager(context));
98-
adapter = new TrackersListAdapter(getContext(), recyclerView, mAppUid);
94+
adapter = new TrackersListAdapter(getContext(), recyclerView, mAppUid, mAppId);
9995
recyclerView.setAdapter(adapter);
10096

10197
swipeRefresh = v.findViewById(R.id.swipeRefresh);
10298
swipeRefresh.setOnRefreshListener(this::updateTrackerList);
10399

104-
emptyView = v.findViewById(R.id.empty);
105-
btnLaunch = v.findViewById(R.id.btnLaunch);
106-
Context c = getContext();
107-
if (c != null) {
108-
Intent intent = c.getPackageManager().getLaunchIntentForPackage(mAppId);
109-
110-
final Intent launch = (intent == null ||
111-
intent.resolveActivity(c.getPackageManager()) == null ? null : intent);
112-
113-
if (launch == null) {
114-
btnLaunch.setVisibility(View.GONE);
115-
} else {
116-
btnLaunch.setOnClickListener(view -> c.startActivity(launch));
117-
}
118-
}
119-
120100
return v;
121101
}
122102

@@ -149,14 +129,6 @@ protected void onPostExecute(List<TrackerCategory> result) {
149129
if (running) {
150130
if (adapter != null) {
151131
adapter.set(result);
152-
153-
if (result.size() == 0) {
154-
emptyView.setVisibility(View.VISIBLE);
155-
recyclerView.setVisibility(View.GONE);
156-
} else {
157-
emptyView.setVisibility(View.GONE);
158-
recyclerView.setVisibility(View.VISIBLE);
159-
}
160132
}
161133

162134
if (swipeRefresh != null) {

app/src/main/java/net/kollnig/missioncontrol/details/TrackersListAdapter.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
package net.kollnig.missioncontrol.details;
1919

2020
import android.content.Context;
21+
import android.content.Intent;
2122
import android.text.TextUtils;
2223
import android.view.LayoutInflater;
2324
import android.view.View;
2425
import android.view.ViewGroup;
26+
import android.widget.Button;
2527
import android.widget.Switch;
2628
import android.widget.TextView;
2729

@@ -49,15 +51,23 @@ public class TrackersListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
4951
private final String TAG = TrackersListAdapter.class.getSimpleName();
5052
private final RecyclerView recyclerView;
5153
private final Integer mAppUid;
54+
private final String mAppId;
5255
private List<TrackerCategory> mValues = new ArrayList<>();
53-
private Context mContext;
56+
private final Context mContext;
57+
private Intent launch;
5458

5559
public TrackersListAdapter(Context c,
5660
RecyclerView root,
57-
Integer appUid) {
61+
Integer appUid,
62+
String appId) {
5863
recyclerView = root;
5964
mContext = c;
6065
mAppUid = appUid;
66+
mAppId = appId;
67+
68+
Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(mAppId);
69+
launch = (intent == null ||
70+
intent.resolveActivity(mContext.getPackageManager()) == null ? null : intent);
6171

6272
// Removes blinks
6373
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
@@ -122,6 +132,12 @@ public void onBindViewHolder(RecyclerView.ViewHolder _holder, int position) {
122132
} else if (_holder instanceof VHHeader) {
123133
VHHeader holder = (VHHeader) _holder;
124134

135+
if (launch == null) {
136+
holder.mLaunch.setVisibility(View.GONE);
137+
} else {
138+
holder.mLaunch.setOnClickListener(view -> mContext.startActivity(launch));
139+
}
140+
125141
final InternetBlocklist w = InternetBlocklist.getInstance(mContext);
126142
holder.mSwitch.setChecked(
127143
w.blockedInternet(mAppUid)
@@ -181,11 +197,13 @@ static class VHItem extends RecyclerView.ViewHolder {
181197
static class VHHeader extends RecyclerView.ViewHolder {
182198
final View mView;
183199
final Switch mSwitch;
200+
final Button mLaunch;
184201

185202
VHHeader(View view) {
186203
super(view);
187204
mView = view;
188205
mSwitch = view.findViewById(R.id.switch_internet);
206+
mLaunch = view.findViewById(R.id.btnLaunch);
189207
}
190208
}
191209
}

app/src/main/res/layout/fragment_trackers.xml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,6 @@
2525
xmlns:app="http://schemas.android.com/apk/res-auto"
2626
tools:mContext="net.kollnig.missioncontrol.details.TrackersFragment">
2727

28-
<LinearLayout
29-
android:id="@+id/empty"
30-
android:layout_height="wrap_content"
31-
android:layout_width="match_parent"
32-
android:orientation="vertical">
33-
34-
<TextView
35-
android:layout_width="wrap_content"
36-
android:layout_height="wrap_content"
37-
android:layout_marginTop="8dp"
38-
android:padding="1dp"
39-
android:paddingStart="?listPreferredItemPaddingLeft"
40-
android:paddingEnd="?listPreferredItemPaddingRight"
41-
android:text="@string/no_trackers"
42-
android:textColor="?android:textColorSecondary"
43-
android:textStyle="italic" />
44-
45-
<LinearLayout
46-
android:layout_width="match_parent"
47-
android:layout_height="wrap_content"
48-
android:layout_margin="8dp"
49-
android:orientation="vertical">
50-
51-
<Button
52-
android:id="@+id/btnLaunch"
53-
android:drawableStart="@drawable/ic_launch_white_24dp"
54-
android:theme="@style/PrimaryButton"
55-
android:layout_width="wrap_content"
56-
android:layout_height="wrap_content"
57-
android:layout_gravity="center_horizontal"
58-
android:text="@string/launch_app"/>
59-
</LinearLayout>
60-
</LinearLayout>
61-
6228
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
6329
android:id="@+id/swipeRefresh"
6430
android:layout_width="match_parent"

app/src/main/res/layout/list_item_trackers_header.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020
android:orientation="vertical"
2121
android:layout_width="match_parent"
2222
android:layout_height="wrap_content">
23-
24-
<TextView
25-
android:id="@+id/textView"
26-
android:minHeight="72dp"
27-
android:paddingStart="?listPreferredItemPaddingLeft"
28-
android:paddingEnd="?listPreferredItemPaddingRight"
23+
<LinearLayout
2924
android:layout_width="match_parent"
3025
android:layout_height="wrap_content"
31-
android:layout_centerInParent="true"
32-
android:text="@string/disclaimer" />
26+
android:layout_margin="8dp"
27+
android:orientation="vertical">
28+
29+
<Button
30+
android:id="@+id/btnLaunch"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:layout_gravity="center_horizontal"
34+
android:drawableStart="@drawable/ic_launch_white_24dp"
35+
android:text="@string/launch_app"
36+
android:theme="@style/PrimaryButton" />
37+
</LinearLayout>
3338

3439
<androidx.cardview.widget.CardView
3540
android:layout_marginBottom="8dp"

app/src/main/res/values-es/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ Please provide your response through secure means by email. I look forward to re
422422
\n
423423
Sincerely,\n\n]]></string>
424424
<string name="packet_statistics">Tráfico de datos</string>
425-
<string name="no_trackers">No se observaron rastreadores. Solo los rastreadores que fueron observados para recoletar sus datos serán mostrados.\n\nIntenta usar la app y revise de nuevo.</string>
426425

427426
<string name="crash_dialog_text">Lo sentimos. TrackerControl dejó de funcionar. ¿Podrías enviar un correo describiendo su funcionamiento?</string>
428427
<string name="crash_dialog_comment">¿Algún comentario?</string>
@@ -431,7 +430,6 @@ Sincerely,\n\n]]></string>
431430
<string name="instructions_monitoring">Conmuta el interruptor e interactúa con otras aplicaciones.</string>
432431

433432
<string name="afterboot_notification">El sistema operativo de su dispositivo no permite monitorear y filtrar las comunicaciones de la red. Esto es necesario para el TrackerControl.</string>
434-
<string name="disclaimer">La información podría estar incompleta o imprecisa.\n\nSi la aplicación no responde, por favor desactiva el bloqueo.</string>
435433

436434
<string name="device_not_supported_title">Dispositivo no soportado</string>
437435
<string name="device_not_supported_msg">El sistema operativo de su dispositivo on opermite monitorizar o filtrar las conexiones de red. Esto es necesario para TrackerControl.</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ Please provide your response through secure means by email. I look forward to re
482482
\n
483483
Sincerely,\n\n]]></string>
484484
<string name="packet_statistics">Data flows</string>
485-
<string name="no_trackers">No trackers observed. Only trackers that were observed to collect your data are shown.\n\nTry using the app and check again..</string>
486485

487486
<string name="crash_dialog_text">Sorry. TrackerControl just crashed.. Would you mind sending us an email with details?</string>
488487
<string name="crash_dialog_comment">Any comments?</string>
@@ -491,12 +490,11 @@ Sincerely,\n\n]]></string>
491490
<string name="instructions_monitoring">Toggle the switch and interact with some apps.</string>
492491

493492
<string name="afterboot_notification">Restart notification</string>
494-
<string name="disclaimer">Shown information may be incomplete or incorrect.\n\nIf an app stops to work, disable blocking.</string>
495493

496494
<string name="device_not_supported_title">Device not supported</string>
497495
<string name="device_not_supported_msg">The operating system of your device does not allow for monitoring and filtering of network communications. This is required for TrackerControl.</string>
498496

499497
<string name="monitor">Monitor</string>
500498

501-
<string name="launch_app">Launch app</string>
499+
<string name="launch_app">Launch &amp; Find trackers</string>
502500
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Add app-wise blocking of ALL internet traffic
2+
- Clarify blocking UI
3+
- Fix necessary trackers (enables updater in GitHub variant)
4+
- Add cookie policy (to underline that this app would never use cookies)
5+
- Add feature-reduced, but PlayStore-compatible variant

0 commit comments

Comments
 (0)