Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions app/src/main/java/eu/faircode/netguard/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,6 @@ else if ("trackers_all".equals(sort))
else
menu.findItem(R.id.menu_sort_trackers_week).setChecked(true);

menu.findItem(R.id.menu_lockdown).setChecked(prefs.getBoolean("lockdown", false));

return super.onPrepareOptionsMenu(menu);
}

Expand Down Expand Up @@ -980,9 +978,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
item.setChecked(true);
prefs.edit().putString("sort", "uid").apply();
return true;
} else if (itemId == R.id.menu_lockdown) {
menu_lockdown(item);
return true;
} else if (itemId == R.id.menu_log) {
if (Util.canFilter(this))
startActivity(new Intent(this, ActivityLog.class));
Expand Down Expand Up @@ -1220,7 +1215,6 @@ private void menu_legend() {
// Create view
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.legend, null, false);
ImageView ivLockdownOn = view.findViewById(R.id.ivLockdownOn);
ImageView ivWifiOn = view.findViewById(R.id.ivWifiOn);
ImageView ivWifiOff = view.findViewById(R.id.ivWifiOff);
ImageView ivOtherOn = view.findViewById(R.id.ivOtherOn);
Expand All @@ -1229,7 +1223,6 @@ private void menu_legend() {
ImageView ivHostAllowed = view.findViewById(R.id.ivHostAllowed);
ImageView ivHostBlocked = view.findViewById(R.id.ivHostBlocked);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Drawable wrapLockdownOn = DrawableCompat.wrap(ivLockdownOn.getDrawable());
Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable());
Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable());
Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable());
Expand All @@ -1238,7 +1231,6 @@ private void menu_legend() {
Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable());
Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable());

DrawableCompat.setTint(wrapLockdownOn, colorOff);
DrawableCompat.setTint(wrapWifiOn, colorOn);
DrawableCompat.setTint(wrapWifiOff, colorOff);
DrawableCompat.setTint(wrapOtherOn, colorOn);
Expand All @@ -1262,13 +1254,6 @@ public void onDismiss(DialogInterface dialogInterface) {
dialogLegend.show();
}

private void menu_lockdown(MenuItem item) {
item.setChecked(!item.isChecked());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("lockdown", item.isChecked()).apply();
ServiceSinkhole.reload("lockdown", this, false);
}

private void menu_about() {
// Create view
LayoutInflater inflater = LayoutInflater.from(this);
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/eu/faircode/netguard/ActivitySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,7 @@ else if ("disable_on_call".equals(name)) {
ServiceSinkhole.reload("changed " + name, this, false);
} else
ServiceSinkhole.reload("changed " + name, this, false);

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

else if ("blocking_mode".equals(name)) {
String mode = prefs.getString(name, BlockingMode.getDefaultMode());
Expand Down Expand Up @@ -1069,10 +1067,6 @@ private void xmlExport(OutputStream _out) throws IOException {
xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "roaming");

serializer.startTag(null, "lockdown");
xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "lockdown");

serializer.startTag(null, "apply");
xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "apply");
Expand Down Expand Up @@ -1262,7 +1256,6 @@ private void xmlImport(InputStream in) throws IOException, SAXException, ParserC
xmlImport(handler.screen_wifi, getSharedPreferences("screen_wifi", Context.MODE_PRIVATE));
xmlImport(handler.screen_other, getSharedPreferences("screen_other", Context.MODE_PRIVATE));
xmlImport(handler.roaming, getSharedPreferences("roaming", Context.MODE_PRIVATE));
xmlImport(handler.lockdown, getSharedPreferences("lockdown", Context.MODE_PRIVATE));
xmlImport(handler.apply, getSharedPreferences("apply", Context.MODE_PRIVATE));
xmlImport(handler.tracker_protect, getSharedPreferences("tracker_protect", Context.MODE_PRIVATE));
xmlImport(handler.notify, getSharedPreferences("notify", Context.MODE_PRIVATE));
Expand Down Expand Up @@ -1317,7 +1310,6 @@ private class XmlImportHandler extends DefaultHandler {
public Map<String, Object> screen_wifi = new HashMap<>();
public Map<String, Object> screen_other = new HashMap<>();
public Map<String, Object> roaming = new HashMap<>();
public Map<String, Object> lockdown = new HashMap<>();
public Map<String, Object> apply = new HashMap<>();
public Map<String, Object> tracker_protect = new HashMap<>();
public Map<String, Object> notify = new HashMap<>();
Expand Down Expand Up @@ -1352,8 +1344,7 @@ else if (qName.equals("screen_other"))
else if (qName.equals("roaming"))
current = roaming;

else if (qName.equals("lockdown"))
current = lockdown;


else if (qName.equals("apply"))
current = apply;
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/eu/faircode/netguard/AdapterRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ private void updateRule(Context context, Rule rule, boolean root, List<Rule> lis
SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE);
SharedPreferences screen_other = context.getSharedPreferences("screen_other", Context.MODE_PRIVATE);
SharedPreferences roaming = context.getSharedPreferences("roaming", Context.MODE_PRIVATE);
SharedPreferences lockdown = context.getSharedPreferences("lockdown", Context.MODE_PRIVATE);
SharedPreferences notify = context.getSharedPreferences("notify", Context.MODE_PRIVATE);

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

if (rule.lockdown)
lockdown.edit().putBoolean(rule.packageName, rule.lockdown).apply();
else
lockdown.edit().remove(rule.packageName).apply();

if (rule.notify)
notify.edit().remove(rule.packageName).apply();
Expand All @@ -401,7 +396,6 @@ private void updateRule(Context context, Rule rule, boolean root, List<Rule> lis
related.screen_wifi = rule.screen_wifi;
related.screen_other = rule.screen_other;
related.roaming = rule.roaming;
related.lockdown = rule.lockdown;
related.notify = rule.notify;
listModified.add(related);
}
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/eu/faircode/netguard/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public class Rule {
public boolean screen_wifi = false;
public boolean screen_other = false;
public boolean roaming = false;
public boolean lockdown = false;

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

rule.apply = apply.getBoolean(info.packageName, true);
rule.tracker_protect = BlockingMode.isTrackerProtectionEnabled(
Expand Down Expand Up @@ -543,7 +540,7 @@ private void updateChanged(boolean default_wifi, boolean default_other, boolean
(wifi_blocked && screen_wifi != screen_wifi_default) ||
(other_blocked && screen_other != screen_other_default) ||
((!other_blocked || screen_other) && roaming != default_roaming) ||
hosts > 0 || lockdown || !tracker_protect || !apply);
hosts > 0 || !tracker_protect || !apply);
}

public void updateChanged(Context context) {
Expand Down
81 changes: 3 additions & 78 deletions app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public class ServiceSinkhole extends VpnService {
private static final int NOTIFY_ENFORCING = 1;
private static final int NOTIFY_WAITING = 2;
private static final int NOTIFY_DISABLED = 3;
private static final int NOTIFY_LOCKDOWN = 4;
private static final int NOTIFY_AUTOSTART = 5;
private static final int NOTIFY_ERROR = 6;
private static final int NOTIFY_TRAFFIC = 7;
Expand Down Expand Up @@ -479,16 +478,6 @@ public void onCallStateChanged(int state, String incomingNumber) {
Log.e(TAG, "Unknown command=" + cmd);
}

if (cmd == Command.start || cmd == Command.reload) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
boolean filter = prefs.getBoolean("filter", false);
if (filter && isLockdownEnabled())
showLockdownNotification();
else
removeLockdownNotification();
}
}

if (cmd == Command.start || cmd == Command.reload || cmd == Command.stop) {
// Update main view
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
Expand Down Expand Up @@ -1850,8 +1839,6 @@ public static void prepareHostsBlocked(Context c) {
}

private void prepareUidIPFilters(String dname) {
SharedPreferences lockdown = getSharedPreferences("lockdown", Context.MODE_PRIVATE);

lock.writeLock().lock();

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

if (isLockedDown(last_metered)) {
String[] pkg;
try {
pkg = getPackageManager().getPackagesForUid(uid);
} catch (SecurityException ignored) {
// Work profile cross-user UID
pkg = null;
}
if (pkg != null && pkg.length > 0) {
if (!lockdown.getBoolean(pkg[0], false))
continue;
}
}

IPKey key = new IPKey(version, protocol, dport, uid);
synchronized (mapUidIPFilters) {
if (!mapUidIPFilters.containsKey(key))
Expand Down Expand Up @@ -1986,17 +1959,6 @@ private void prepareForwarding() {
lock.writeLock().unlock();
}

private boolean isLockedDown(boolean metered) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this);
boolean lockdown = prefs.getBoolean("lockdown", false);
boolean lockdown_wifi = prefs.getBoolean("lockdown_wifi", true);
boolean lockdown_other = prefs.getBoolean("lockdown_other", true);
if (metered ? !lockdown_other : !lockdown_wifi)
lockdown = false;

return lockdown;
}

private List<Rule> getAllowedRules(List<Rule> listRule) {
List<Rule> listAllowed = new ArrayList<>();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -2033,8 +1995,6 @@ private List<Rule> getAllowedRules(List<Rule> listRule) {
metered = false;
last_metered = metered;

boolean lockdown = isLockedDown(last_metered);

// Update roaming state
if (roaming && eu)
roaming = !Util.isEU(this);
Expand All @@ -2050,16 +2010,14 @@ private List<Rule> getAllowedRules(List<Rule> listRule) {
" roaming=" + roaming + "/" + org_roaming +
" interactive=" + last_interactive +
" tethering=" + tethering +
" filter=" + filter +
" lockdown=" + lockdown);
" filter=" + filter);

if (last_connected)
for (Rule rule : listRule) {
boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
boolean screen = (metered ? rule.screen_other : rule.screen_wifi);
if ((!blocked || (screen && last_interactive)) &&
(!metered || !(rule.roaming && roaming)) &&
(!lockdown || rule.lockdown))
(!metered || !(rule.roaming && roaming)))
listAllowed.add(rule);
}

Expand Down Expand Up @@ -2673,8 +2631,6 @@ public void onReceive(Context context, Intent intent) {
.apply();
context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName)
.apply();
context.getSharedPreferences("lockdown", Context.MODE_PRIVATE).edit().remove(packageName)
.apply();
context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
BlockingMode.clearAutoExcludedApp(context, packageName);
context.getSharedPreferences("tracker_protect", Context.MODE_PRIVATE).edit().remove(packageName).apply();
Expand Down Expand Up @@ -3294,8 +3250,7 @@ private Notification getEnforcingNotification(int allowed, int blocked, int host
int pause = Integer.parseInt(prefs.getString("pause", "10"));

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "foreground");
builder.setSmallIcon(
isLockedDown(last_metered) ? R.drawable.ic_lock_outline_white_24dp : R.drawable.ic_rocket_white)
builder.setSmallIcon(R.drawable.ic_rocket_white)
.setContentIntent(pi)
.setColor(getResources().getColor(R.color.colorTrackerControl))
.setOngoing(true)
Expand Down Expand Up @@ -3406,37 +3361,7 @@ private void showDisabledNotification() {
NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

private void showLockdownNotification() {
Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
PendingIntent pi = PendingIntentCompat.getActivity(this, NOTIFY_LOCKDOWN, intent,
PendingIntent.FLAG_UPDATE_CURRENT);

TypedValue tv = new TypedValue();
getTheme().resolveAttribute(R.attr.colorOff, tv, true);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify");
builder.setSmallIcon(R.drawable.ic_error_white_24dp)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.msg_always_on_lockdown))
.setContentIntent(pi)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setColor(tv.data)
.setOngoing(false)
.setAutoCancel(true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
builder.setCategory(NotificationCompat.CATEGORY_STATUS)
.setVisibility(NotificationCompat.VISIBILITY_SECRET);

NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
notification.bigText(getString(R.string.msg_always_on_lockdown));

if (Util.canNotify(this))
NotificationManagerCompat.from(this).notify(NOTIFY_LOCKDOWN, notification.build());
}

private void removeLockdownNotification() {
NotificationManagerCompat.from(this).cancel(NOTIFY_LOCKDOWN);
}

private void showAutoStartNotification() {
Intent main = new Intent(this, ActivityMain.class);
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/res/layout/legend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,6 @@
android:textAppearance="@style/TextMedium"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/ivLockdownOn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:src="@drawable/lockdown_on"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/title_lockdown_enabled"
android:textAppearance="@style/TextMedium"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
</group>
</menu>
</item>
<item
android:id="@+id/menu_lockdown"
android:checkable="true"
android:visible="false"
android:title="@string/setting_lockdown"/>
<item
android:id="@+id/menu_log"
android:title="@string/menu_log"/>
Expand Down
Loading