mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-24 07:10:50 +00:00
Added setting to disable 'when screen on' condition
This commit is contained in:
parent
1827865cf9
commit
9941f042c3
8 changed files with 53 additions and 17 deletions
|
@ -553,6 +553,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
swEnabled.setChecked(enabled);
|
||||
|
||||
} else if ("whitelist_wifi".equals(name) ||
|
||||
"screen_on".equals(name) ||
|
||||
"screen_wifi".equals(name) ||
|
||||
"whitelist_other".equals(name) ||
|
||||
"screen_other".equals(name) ||
|
||||
|
@ -566,10 +567,11 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
updateApplicationList(null);
|
||||
|
||||
final LinearLayout llWhitelist = (LinearLayout) findViewById(R.id.llWhitelist);
|
||||
boolean screen_on = prefs.getBoolean("screen_on", true);
|
||||
boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false);
|
||||
boolean whitelist_other = prefs.getBoolean("whitelist_other", false);
|
||||
boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true);
|
||||
llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && hintWhitelist ? View.VISIBLE : View.GONE);
|
||||
llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && screen_on && hintWhitelist ? View.VISIBLE : View.GONE);
|
||||
|
||||
} else if ("manage_system".equals(name)) {
|
||||
invalidateOptionsMenu();
|
||||
|
|
|
@ -497,7 +497,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
prefs.edit().remove(name).apply();
|
||||
|
||||
// Dependencies
|
||||
if ("whitelist_wifi".equals(name) ||
|
||||
if ("screen_on".equals(name))
|
||||
ServiceSinkhole.reload("changed " + name, this);
|
||||
|
||||
else if ("whitelist_wifi".equals(name) ||
|
||||
"screen_wifi".equals(name))
|
||||
ServiceSinkhole.reload("changed " + name, this);
|
||||
|
||||
|
|
|
@ -337,6 +337,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
}
|
||||
}.execute();
|
||||
|
||||
boolean screen_on = prefs.getBoolean("screen_on", true);
|
||||
|
||||
// Wi-Fi settings
|
||||
holder.cbWifi.setEnabled(rule.apply);
|
||||
holder.cbWifi.setAlpha(wifiActive ? 1 : 0.5f);
|
||||
|
@ -356,7 +358,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
|
||||
holder.ivScreenWifi.setEnabled(rule.apply);
|
||||
holder.ivScreenWifi.setAlpha(wifiActive ? 1 : 0.5f);
|
||||
holder.ivScreenWifi.setVisibility(rule.screen_wifi && rule.wifi_blocked ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.ivScreenWifi.setVisibility(rule.screen_wifi && rule.wifi_blocked && screen_on ? View.VISIBLE : View.INVISIBLE);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
Drawable wrap = DrawableCompat.wrap(holder.ivScreenWifi.getDrawable());
|
||||
DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed);
|
||||
|
@ -381,7 +383,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
|
|||
|
||||
holder.ivScreenOther.setEnabled(rule.apply);
|
||||
holder.ivScreenOther.setAlpha(otherActive ? 1 : 0.5f);
|
||||
holder.ivScreenOther.setVisibility(rule.screen_other && rule.other_blocked ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.ivScreenOther.setVisibility(rule.screen_other && rule.other_blocked && screen_on ? View.VISIBLE : View.INVISIBLE);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
Drawable wrap = DrawableCompat.wrap(holder.ivScreenOther.getDrawable());
|
||||
DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed);
|
||||
|
|
|
@ -275,12 +275,17 @@ public class Rule {
|
|||
boolean default_screen_wifi = prefs.getBoolean("screen_wifi", true);
|
||||
boolean default_screen_other = prefs.getBoolean("screen_other", true);
|
||||
boolean default_roaming = prefs.getBoolean("whitelist_roaming", true);
|
||||
|
||||
boolean manage_system = prefs.getBoolean("manage_system", false);
|
||||
boolean screen_on = prefs.getBoolean("screen_on", true);
|
||||
boolean show_user = prefs.getBoolean("show_user", true);
|
||||
boolean show_system = prefs.getBoolean("show_system", false);
|
||||
boolean show_nointernet = prefs.getBoolean("show_nointernet", true);
|
||||
boolean show_disabled = prefs.getBoolean("show_disabled", true);
|
||||
|
||||
default_screen_wifi = default_screen_wifi && screen_on;
|
||||
default_screen_other = default_screen_other && screen_on;
|
||||
|
||||
long now = SystemClock.elapsedRealtime();
|
||||
|
||||
// Get predefined rules
|
||||
|
@ -380,8 +385,8 @@ public class Rule {
|
|||
|
||||
rule.wifi_blocked = (!(rule.system && !manage_system) && wifi.getBoolean(info.packageName, rule.wifi_default));
|
||||
rule.other_blocked = (!(rule.system && !manage_system) && other.getBoolean(info.packageName, rule.other_default));
|
||||
rule.screen_wifi = screen_wifi.getBoolean(info.packageName, rule.screen_wifi_default);
|
||||
rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default);
|
||||
rule.screen_wifi = screen_wifi.getBoolean(info.packageName, rule.screen_wifi_default) && screen_on;
|
||||
rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default) && screen_on;
|
||||
rule.roaming = roaming.getBoolean(info.packageName, rule.roaming_default);
|
||||
|
||||
rule.apply = apply.getBoolean(info.packageName, true);
|
||||
|
@ -477,8 +482,9 @@ public class Rule {
|
|||
|
||||
public void updateChanged(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean default_wifi = prefs.getBoolean("whitelist_wifi", true);
|
||||
boolean default_other = prefs.getBoolean("whitelist_other", true);
|
||||
boolean screen_on = prefs.getBoolean("screen_on", false);
|
||||
boolean default_wifi = prefs.getBoolean("whitelist_wifi", true) && screen_on;
|
||||
boolean default_other = prefs.getBoolean("whitelist_other", true) && screen_on;
|
||||
boolean default_roaming = prefs.getBoolean("whitelist_roaming", true);
|
||||
updateChanged(default_wifi, default_other, default_roaming);
|
||||
}
|
||||
|
|
|
@ -282,6 +282,25 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
return;
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("screen_on", true)) {
|
||||
Log.i(TAG, "Started listening for interactive state changes");
|
||||
if (prefs.getBoolean("screen_on", true)) {
|
||||
last_interactive = Util.isInteractive(ServiceSinkhole.this);
|
||||
IntentFilter ifInteractive = new IntentFilter();
|
||||
ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
|
||||
ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED);
|
||||
registerReceiver(interactiveStateReceiver, ifInteractive);
|
||||
registeredInteractiveState = true;
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "Stopped listening for interactive state changes");
|
||||
if (registeredInteractiveState) {
|
||||
unregisterReceiver(interactiveStateReceiver);
|
||||
registeredInteractiveState = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for phone state changes
|
||||
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (tm != null && !phone_state &&
|
||||
|
@ -1798,15 +1817,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
|||
logHandler = new LogHandler(logLooper);
|
||||
statsHandler = new StatsHandler(statsLooper);
|
||||
|
||||
// Listen for interactive state changes
|
||||
last_interactive = Util.isInteractive(this);
|
||||
IntentFilter ifInteractive = new IntentFilter();
|
||||
ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
|
||||
ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED);
|
||||
registerReceiver(interactiveStateReceiver, ifInteractive);
|
||||
registeredInteractiveState = true;
|
||||
|
||||
// Listen for power save mode
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) {
|
||||
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
|
|
|
@ -65,6 +65,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="setting_theme">Theme: %1$s</string>
|
||||
<string name="setting_dark">Use dark theme</string>
|
||||
<string name="setting_install">Notify on new install</string>
|
||||
<string name="setting_screen_on">Apply \'when screen on\' rules</string>
|
||||
<string name="setting_auto">Auto enable after %1$s minutes</string>
|
||||
<string name="setting_delay">Delay screen off %1$s minutes</string>
|
||||
<string name="setting_update">Check for updates</string>
|
||||
|
|
|
@ -14,12 +14,18 @@
|
|||
android:defaultValue="true"
|
||||
android:key="whitelist_other"
|
||||
android:title="@string/setting_whitelist_other" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="screen_on"
|
||||
android:title="@string/setting_screen_on" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:dependency="screen_on"
|
||||
android:key="screen_wifi"
|
||||
android:title="@string/setting_screen_wifi" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:dependency="screen_on"
|
||||
android:key="screen_other"
|
||||
android:title="@string/setting_screen_other" />
|
||||
<CheckBoxPreference
|
||||
|
|
|
@ -14,12 +14,18 @@
|
|||
android:defaultValue="true"
|
||||
android:key="whitelist_other"
|
||||
android:title="@string/setting_whitelist_other" />
|
||||
<eu.faircode.netguard.SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="screen_on"
|
||||
android:title="@string/setting_screen_on" />
|
||||
<eu.faircode.netguard.SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:dependency="screen_on"
|
||||
android:key="screen_wifi"
|
||||
android:title="@string/setting_screen_wifi" />
|
||||
<eu.faircode.netguard.SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:dependency="screen_on"
|
||||
android:key="screen_other"
|
||||
android:title="@string/setting_screen_other" />
|
||||
<eu.faircode.netguard.SwitchPreference
|
||||
|
|
Loading…
Reference in a new issue