Skip to content

Commit a65fe60

Browse files
committed
Remove NetGuard lockdown feature (hidden/unused in TC)
NetGuard's app lockdown feature was hidden in TrackerControl (menu_lockdown had android:visible="false") and the "lockdown" pref defaulted to false with no UI to enable it. Remove all related code: - ServiceSinkhole: isLockedDown(), prepareUidIPFilters lockdown check, NOTIFY_LOCKDOWN constant, showLockdownNotification/removeLockdownNotification, notification icon lock/rocket conditional, lockdown SharedPreferences cleanup - Rule: lockdown field and SharedPreferences loading - AdapterRule: lockdown persistence and related-app propagation - ActivityMain: hidden menu item handler, legend lockdown icon - ActivitySettings: lockdown_wifi/lockdown_other pref listener, lockdown export/import in XML backup - XML: menu_lockdown item, legend lockdown entry Note: Android system VPN lockdown detection (always_on_vpn_lockdown in Settings.Secure) used in ActivityOnboarding and ActivityMain is preserved — that's a different feature that warns users about the system "Block connections without VPN" setting. https://claude.ai/code/session_01PuXevPG3gUKEXWHrgRMptV
1 parent 3bd977c commit a65fe60

7 files changed

Lines changed: 6 additions & 141 deletions

File tree

app/src/main/java/eu/faircode/netguard/ActivityMain.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,6 @@ else if ("trackers_all".equals(sort))
936936
else
937937
menu.findItem(R.id.menu_sort_trackers_week).setChecked(true);
938938

939-
menu.findItem(R.id.menu_lockdown).setChecked(prefs.getBoolean("lockdown", false));
940-
941939
return super.onPrepareOptionsMenu(menu);
942940
}
943941

@@ -980,9 +978,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
980978
item.setChecked(true);
981979
prefs.edit().putString("sort", "uid").apply();
982980
return true;
983-
} else if (itemId == R.id.menu_lockdown) {
984-
menu_lockdown(item);
985-
return true;
986981
} else if (itemId == R.id.menu_log) {
987982
if (Util.canFilter(this))
988983
startActivity(new Intent(this, ActivityLog.class));
@@ -1220,7 +1215,6 @@ private void menu_legend() {
12201215
// Create view
12211216
LayoutInflater inflater = LayoutInflater.from(this);
12221217
View view = inflater.inflate(R.layout.legend, null, false);
1223-
ImageView ivLockdownOn = view.findViewById(R.id.ivLockdownOn);
12241218
ImageView ivWifiOn = view.findViewById(R.id.ivWifiOn);
12251219
ImageView ivWifiOff = view.findViewById(R.id.ivWifiOff);
12261220
ImageView ivOtherOn = view.findViewById(R.id.ivOtherOn);
@@ -1229,7 +1223,6 @@ private void menu_legend() {
12291223
ImageView ivHostAllowed = view.findViewById(R.id.ivHostAllowed);
12301224
ImageView ivHostBlocked = view.findViewById(R.id.ivHostBlocked);
12311225
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
1232-
Drawable wrapLockdownOn = DrawableCompat.wrap(ivLockdownOn.getDrawable());
12331226
Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable());
12341227
Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable());
12351228
Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable());
@@ -1238,7 +1231,6 @@ private void menu_legend() {
12381231
Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable());
12391232
Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable());
12401233

1241-
DrawableCompat.setTint(wrapLockdownOn, colorOff);
12421234
DrawableCompat.setTint(wrapWifiOn, colorOn);
12431235
DrawableCompat.setTint(wrapWifiOff, colorOff);
12441236
DrawableCompat.setTint(wrapOtherOn, colorOn);
@@ -1262,13 +1254,6 @@ public void onDismiss(DialogInterface dialogInterface) {
12621254
dialogLegend.show();
12631255
}
12641256

1265-
private void menu_lockdown(MenuItem item) {
1266-
item.setChecked(!item.isChecked());
1267-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
1268-
prefs.edit().putBoolean("lockdown", item.isChecked()).apply();
1269-
ServiceSinkhole.reload("lockdown", this, false);
1270-
}
1271-
12721257
private void menu_about() {
12731258
// Create view
12741259
LayoutInflater inflater = LayoutInflater.from(this);

app/src/main/java/eu/faircode/netguard/ActivitySettings.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,7 @@ else if ("disable_on_call".equals(name)) {
590590
} else
591591
ServiceSinkhole.reload("changed " + name, this, false);
592592

593-
} else if ("lockdown_wifi".equals(name) || "lockdown_other".equals(name))
594-
ServiceSinkhole.reload("changed " + name, this, false);
593+
595594

596595
else if ("blocking_mode".equals(name)) {
597596
String mode = prefs.getString(name, BlockingMode.getDefaultMode());
@@ -1069,10 +1068,6 @@ private void xmlExport(OutputStream _out) throws IOException {
10691068
xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer);
10701069
serializer.endTag(null, "roaming");
10711070

1072-
serializer.startTag(null, "lockdown");
1073-
xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer);
1074-
serializer.endTag(null, "lockdown");
1075-
10761071
serializer.startTag(null, "apply");
10771072
xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer);
10781073
serializer.endTag(null, "apply");
@@ -1262,7 +1257,6 @@ private void xmlImport(InputStream in) throws IOException, SAXException, ParserC
12621257
xmlImport(handler.screen_wifi, getSharedPreferences("screen_wifi", Context.MODE_PRIVATE));
12631258
xmlImport(handler.screen_other, getSharedPreferences("screen_other", Context.MODE_PRIVATE));
12641259
xmlImport(handler.roaming, getSharedPreferences("roaming", Context.MODE_PRIVATE));
1265-
xmlImport(handler.lockdown, getSharedPreferences("lockdown", Context.MODE_PRIVATE));
12661260
xmlImport(handler.apply, getSharedPreferences("apply", Context.MODE_PRIVATE));
12671261
xmlImport(handler.tracker_protect, getSharedPreferences("tracker_protect", Context.MODE_PRIVATE));
12681262
xmlImport(handler.notify, getSharedPreferences("notify", Context.MODE_PRIVATE));
@@ -1317,7 +1311,6 @@ private class XmlImportHandler extends DefaultHandler {
13171311
public Map<String, Object> screen_wifi = new HashMap<>();
13181312
public Map<String, Object> screen_other = new HashMap<>();
13191313
public Map<String, Object> roaming = new HashMap<>();
1320-
public Map<String, Object> lockdown = new HashMap<>();
13211314
public Map<String, Object> apply = new HashMap<>();
13221315
public Map<String, Object> tracker_protect = new HashMap<>();
13231316
public Map<String, Object> notify = new HashMap<>();
@@ -1352,8 +1345,7 @@ else if (qName.equals("screen_other"))
13521345
else if (qName.equals("roaming"))
13531346
current = roaming;
13541347

1355-
else if (qName.equals("lockdown"))
1356-
current = lockdown;
1348+
13571349

13581350
else if (qName.equals("apply"))
13591351
current = apply;

app/src/main/java/eu/faircode/netguard/AdapterRule.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ private void updateRule(Context context, Rule rule, boolean root, List<Rule> lis
345345
SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE);
346346
SharedPreferences screen_other = context.getSharedPreferences("screen_other", Context.MODE_PRIVATE);
347347
SharedPreferences roaming = context.getSharedPreferences("roaming", Context.MODE_PRIVATE);
348-
SharedPreferences lockdown = context.getSharedPreferences("lockdown", Context.MODE_PRIVATE);
349348
SharedPreferences notify = context.getSharedPreferences("notify", Context.MODE_PRIVATE);
350349

351350
if (rule.wifi_blocked == rule.wifi_default)
@@ -377,10 +376,6 @@ private void updateRule(Context context, Rule rule, boolean root, List<Rule> lis
377376
else
378377
roaming.edit().putBoolean(rule.packageName, rule.roaming).apply();
379378

380-
if (rule.lockdown)
381-
lockdown.edit().putBoolean(rule.packageName, rule.lockdown).apply();
382-
else
383-
lockdown.edit().remove(rule.packageName).apply();
384379

385380
if (rule.notify)
386381
notify.edit().remove(rule.packageName).apply();
@@ -401,7 +396,6 @@ private void updateRule(Context context, Rule rule, boolean root, List<Rule> lis
401396
related.screen_wifi = rule.screen_wifi;
402397
related.screen_other = rule.screen_other;
403398
related.roaming = rule.roaming;
404-
related.lockdown = rule.lockdown;
405399
related.notify = rule.notify;
406400
listModified.add(related);
407401
}

app/src/main/java/eu/faircode/netguard/Rule.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public class Rule {
8181
public boolean screen_wifi = false;
8282
public boolean screen_other = false;
8383
public boolean roaming = false;
84-
public boolean lockdown = false;
8584

8685
public boolean apply = true; // If false, completely exclude from VPN (no DNS, no routing)
8786
public boolean tracker_protect = true; // If false, don't block trackers (but still route through VPN)
@@ -240,7 +239,6 @@ public static List<Rule> getRules(final boolean all, boolean self, Context conte
240239
SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE);
241240
SharedPreferences screen_other = context.getSharedPreferences("screen_other", Context.MODE_PRIVATE);
242241
SharedPreferences roaming = context.getSharedPreferences("roaming", Context.MODE_PRIVATE);
243-
SharedPreferences lockdown = context.getSharedPreferences("lockdown", Context.MODE_PRIVATE);
244242
SharedPreferences apply = context.getSharedPreferences("apply", Context.MODE_PRIVATE);
245243
SharedPreferences tracker_protect = context.getSharedPreferences("tracker_protect", Context.MODE_PRIVATE);
246244
SharedPreferences notify = context.getSharedPreferences("notify", Context.MODE_PRIVATE);
@@ -413,7 +411,6 @@ public static List<Rule> getRules(final boolean all, boolean self, Context conte
413411
rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default)
414412
&& screen_on;
415413
rule.roaming = roaming.getBoolean(info.packageName, rule.roaming_default);
416-
rule.lockdown = lockdown.getBoolean(info.packageName, false);
417414

418415
rule.apply = apply.getBoolean(info.packageName, true);
419416
rule.tracker_protect = BlockingMode.isTrackerProtectionEnabled(
@@ -543,7 +540,7 @@ private void updateChanged(boolean default_wifi, boolean default_other, boolean
543540
(wifi_blocked && screen_wifi != screen_wifi_default) ||
544541
(other_blocked && screen_other != screen_other_default) ||
545542
((!other_blocked || screen_other) && roaming != default_roaming) ||
546-
hosts > 0 || lockdown || !tracker_protect || !apply);
543+
hosts > 0 || !tracker_protect || !apply);
547544
}
548545

549546
public void updateChanged(Context context) {

app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public class ServiceSinkhole extends VpnService {
184184
private static final int NOTIFY_ENFORCING = 1;
185185
private static final int NOTIFY_WAITING = 2;
186186
private static final int NOTIFY_DISABLED = 3;
187-
private static final int NOTIFY_LOCKDOWN = 4;
188187
private static final int NOTIFY_AUTOSTART = 5;
189188
private static final int NOTIFY_ERROR = 6;
190189
private static final int NOTIFY_TRAFFIC = 7;
@@ -479,16 +478,6 @@ public void onCallStateChanged(int state, String incomingNumber) {
479478
Log.e(TAG, "Unknown command=" + cmd);
480479
}
481480

482-
if (cmd == Command.start || cmd == Command.reload) {
483-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
484-
boolean filter = prefs.getBoolean("filter", false);
485-
if (filter && isLockdownEnabled())
486-
showLockdownNotification();
487-
else
488-
removeLockdownNotification();
489-
}
490-
}
491-
492481
if (cmd == Command.start || cmd == Command.reload || cmd == Command.stop) {
493482
// Update main view
494483
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
@@ -1850,8 +1839,6 @@ public static void prepareHostsBlocked(Context c) {
18501839
}
18511840

18521841
private void prepareUidIPFilters(String dname) {
1853-
SharedPreferences lockdown = getSharedPreferences("lockdown", Context.MODE_PRIVATE);
1854-
18551842
lock.writeLock().lock();
18561843

18571844
if (dname == null) // reset mechanism, called from startNative()
@@ -1878,20 +1865,6 @@ private void prepareUidIPFilters(String dname) {
18781865
long time = (cursor.isNull(colTime) ? new Date().getTime() : cursor.getLong(colTime));
18791866
long ttl = (cursor.isNull(colTTL) ? 7 * 24 * 3600 * 1000L : cursor.getLong(colTTL));
18801867

1881-
if (isLockedDown(last_metered)) {
1882-
String[] pkg;
1883-
try {
1884-
pkg = getPackageManager().getPackagesForUid(uid);
1885-
} catch (SecurityException ignored) {
1886-
// Work profile cross-user UID
1887-
pkg = null;
1888-
}
1889-
if (pkg != null && pkg.length > 0) {
1890-
if (!lockdown.getBoolean(pkg[0], false))
1891-
continue;
1892-
}
1893-
}
1894-
18951868
IPKey key = new IPKey(version, protocol, dport, uid);
18961869
synchronized (mapUidIPFilters) {
18971870
if (!mapUidIPFilters.containsKey(key))
@@ -1986,17 +1959,6 @@ private void prepareForwarding() {
19861959
lock.writeLock().unlock();
19871960
}
19881961

1989-
private boolean isLockedDown(boolean metered) {
1990-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this);
1991-
boolean lockdown = prefs.getBoolean("lockdown", false);
1992-
boolean lockdown_wifi = prefs.getBoolean("lockdown_wifi", true);
1993-
boolean lockdown_other = prefs.getBoolean("lockdown_other", true);
1994-
if (metered ? !lockdown_other : !lockdown_wifi)
1995-
lockdown = false;
1996-
1997-
return lockdown;
1998-
}
1999-
20001962
private List<Rule> getAllowedRules(List<Rule> listRule) {
20011963
List<Rule> listAllowed = new ArrayList<>();
20021964
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -2033,8 +1995,6 @@ private List<Rule> getAllowedRules(List<Rule> listRule) {
20331995
metered = false;
20341996
last_metered = metered;
20351997

2036-
boolean lockdown = isLockedDown(last_metered);
2037-
20381998
// Update roaming state
20391999
if (roaming && eu)
20402000
roaming = !Util.isEU(this);
@@ -2050,16 +2010,14 @@ private List<Rule> getAllowedRules(List<Rule> listRule) {
20502010
" roaming=" + roaming + "/" + org_roaming +
20512011
" interactive=" + last_interactive +
20522012
" tethering=" + tethering +
2053-
" filter=" + filter +
2054-
" lockdown=" + lockdown);
2013+
" filter=" + filter);
20552014

20562015
if (last_connected)
20572016
for (Rule rule : listRule) {
20582017
boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
20592018
boolean screen = (metered ? rule.screen_other : rule.screen_wifi);
20602019
if ((!blocked || (screen && last_interactive)) &&
2061-
(!metered || !(rule.roaming && roaming)) &&
2062-
(!lockdown || rule.lockdown))
2020+
(!metered || !(rule.roaming && roaming)))
20632021
listAllowed.add(rule);
20642022
}
20652023

@@ -2673,8 +2631,6 @@ public void onReceive(Context context, Intent intent) {
26732631
.apply();
26742632
context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName)
26752633
.apply();
2676-
context.getSharedPreferences("lockdown", Context.MODE_PRIVATE).edit().remove(packageName)
2677-
.apply();
26782634
context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
26792635
BlockingMode.clearAutoExcludedApp(context, packageName);
26802636
context.getSharedPreferences("tracker_protect", Context.MODE_PRIVATE).edit().remove(packageName).apply();
@@ -3294,8 +3250,7 @@ private Notification getEnforcingNotification(int allowed, int blocked, int host
32943250
int pause = Integer.parseInt(prefs.getString("pause", "10"));
32953251

32963252
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "foreground");
3297-
builder.setSmallIcon(
3298-
isLockedDown(last_metered) ? R.drawable.ic_lock_outline_white_24dp : R.drawable.ic_rocket_white)
3253+
builder.setSmallIcon(R.drawable.ic_rocket_white)
32993254
.setContentIntent(pi)
33003255
.setColor(getResources().getColor(R.color.colorTrackerControl))
33013256
.setOngoing(true)
@@ -3406,37 +3361,7 @@ private void showDisabledNotification() {
34063361
NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
34073362
}
34083363

3409-
private void showLockdownNotification() {
3410-
Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
3411-
PendingIntent pi = PendingIntentCompat.getActivity(this, NOTIFY_LOCKDOWN, intent,
3412-
PendingIntent.FLAG_UPDATE_CURRENT);
3413-
3414-
TypedValue tv = new TypedValue();
3415-
getTheme().resolveAttribute(R.attr.colorOff, tv, true);
3416-
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify");
3417-
builder.setSmallIcon(R.drawable.ic_error_white_24dp)
3418-
.setContentTitle(getString(R.string.app_name))
3419-
.setContentText(getString(R.string.msg_always_on_lockdown))
3420-
.setContentIntent(pi)
3421-
.setPriority(NotificationCompat.PRIORITY_HIGH)
3422-
.setColor(tv.data)
3423-
.setOngoing(false)
3424-
.setAutoCancel(true);
3425-
3426-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
3427-
builder.setCategory(NotificationCompat.CATEGORY_STATUS)
3428-
.setVisibility(NotificationCompat.VISIBILITY_SECRET);
3429-
3430-
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
3431-
notification.bigText(getString(R.string.msg_always_on_lockdown));
34323364

3433-
if (Util.canNotify(this))
3434-
NotificationManagerCompat.from(this).notify(NOTIFY_LOCKDOWN, notification.build());
3435-
}
3436-
3437-
private void removeLockdownNotification() {
3438-
NotificationManagerCompat.from(this).cancel(NOTIFY_LOCKDOWN);
3439-
}
34403365

34413366
private void showAutoStartNotification() {
34423367
Intent main = new Intent(this, ActivityMain.class);

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,6 @@
132132
android:textAppearance="@style/TextMedium"/>
133133
</LinearLayout>
134134

135-
<LinearLayout
136-
android:layout_width="match_parent"
137-
android:layout_height="wrap_content"
138-
android:orientation="horizontal">
139-
140-
<ImageView
141-
android:id="@+id/ivLockdownOn"
142-
android:layout_width="24dp"
143-
android:layout_height="24dp"
144-
android:layout_gravity="center_vertical"
145-
android:layout_margin="4dp"
146-
android:src="@drawable/lockdown_on"/>
147-
148-
<TextView
149-
android:layout_width="wrap_content"
150-
android:layout_height="wrap_content"
151-
android:layout_gravity="center_vertical"
152-
android:layout_marginLeft="8dp"
153-
android:layout_marginStart="8dp"
154-
android:text="@string/title_lockdown_enabled"
155-
android:textAppearance="@style/TextMedium"/>
156-
</LinearLayout>
157-
158135
<LinearLayout
159136
android:layout_width="match_parent"
160137
android:layout_height="wrap_content"

app/src/main/res/menu/main.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
</group>
5151
</menu>
5252
</item>
53-
<item
54-
android:id="@+id/menu_lockdown"
55-
android:checkable="true"
56-
android:visible="false"
57-
android:title="@string/setting_lockdown"/>
5853
<item
5954
android:id="@+id/menu_log"
6055
android:title="@string/menu_log"/>

0 commit comments

Comments
 (0)