Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ please see [this FAQ](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-c

NetGuard is not supported for apps installed in a [work profile](https://developer.android.com/work/managed-profiles),
or in a [Secure Folder](https://www.samsung.com/uk/support/mobile-devices/what-is-the-secure-folder-and-how-do-i-use-it/) (Samsung),
or as second instance (MIUI)
or as second instance (MIUI), or as Parallel app (OnePlus),
because the Android VPN service too often does not work correctly in this situation, which can't be fixed by NetGuard.

Filtering mode cannot be used on [CopperheadOS](https://copperhead.co/android/).
Expand Down
17 changes: 11 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ android {

defaultConfig {
applicationId = "eu.faircode.netguard"
versionName = "2.295"
versionName = "2.296"
minSdkVersion 22
targetSdkVersion 30
versionCode = 2021032201
versionCode = 2021061401
archivesBaseName = "NetGuard-v$versionName"

externalNativeBuild {
Expand All @@ -23,7 +23,7 @@ android {
}
}

//ndkVersion "21.0.6113669"
ndkVersion "21.4.7075529"
ndk {
// https://developer.android.com/ndk/guides/abis.html#sa
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
Expand Down Expand Up @@ -76,18 +76,23 @@ android {
buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/NetGuard/releases/latest\""
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// https://developer.android.com/jetpack/androidx/releases/
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
annotationProcessor 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'androidx.annotation:annotation:1.2.0'

// https://bumptech.github.io/glide/
implementation('com.github.bumptech.glide:glide:4.11.0') {
Expand Down
37 changes: 21 additions & 16 deletions app/src/main/java/eu/faircode/netguard/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,29 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("enabled", isChecked).apply();

if (isChecked) {
String alwaysOn = Settings.Secure.getString(getContentResolver(), "always_on_vpn_app");
Log.i(TAG, "Always-on=" + alwaysOn);
if (!TextUtils.isEmpty(alwaysOn))
if (getPackageName().equals(alwaysOn)) {
if (prefs.getBoolean("filter", false)) {
int lockdown = Settings.Secure.getInt(getContentResolver(), "always_on_vpn_lockdown", 0);
Log.i(TAG, "Lockdown=" + lockdown);
if (lockdown != 0) {
swEnabled.setChecked(false);
Toast.makeText(ActivityMain.this, R.string.msg_always_on_lockdown, Toast.LENGTH_LONG).show();
return;
try {
String alwaysOn = Settings.Secure.getString(getContentResolver(), "always_on_vpn_app");
Log.i(TAG, "Always-on=" + alwaysOn);
if (!TextUtils.isEmpty(alwaysOn))
if (getPackageName().equals(alwaysOn)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q &&
prefs.getBoolean("filter", false)) {
int lockdown = Settings.Secure.getInt(getContentResolver(), "always_on_vpn_lockdown", 0);
Log.i(TAG, "Lockdown=" + lockdown);
if (lockdown != 0) {
swEnabled.setChecked(false);
Toast.makeText(ActivityMain.this, R.string.msg_always_on_lockdown, Toast.LENGTH_LONG).show();
return;
}
}
} else {
swEnabled.setChecked(false);
Toast.makeText(ActivityMain.this, R.string.msg_always_on, Toast.LENGTH_LONG).show();
return;
}
} else {
swEnabled.setChecked(false);
Toast.makeText(ActivityMain.this, R.string.msg_always_on, Toast.LENGTH_LONG).show();
return;
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}

boolean filter = prefs.getBoolean("filter", false);
if (filter && Util.isPrivateDns(ActivityMain.this))
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/eu/faircode/netguard/ApplicationEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ private void createNotificationChannels() {

NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT);
notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
notify.setBypassDnd(true);
nm.createNotificationChannel(notify);

NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT);
access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
access.setBypassDnd(true);
nm.createNotificationChannel(access);
}
}
54 changes: 48 additions & 6 deletions app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import android.os.PowerManager;
import android.os.Process;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.Spannable;
Expand Down Expand Up @@ -160,12 +161,13 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
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_AUTOSTART = 4;
private static final int NOTIFY_ERROR = 5;
private static final int NOTIFY_TRAFFIC = 6;
private static final int NOTIFY_UPDATE = 7;
public static final int NOTIFY_EXTERNAL = 8;
public static final int NOTIFY_DOWNLOAD = 9;
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;
private static final int NOTIFY_UPDATE = 8;
public static final int NOTIFY_EXTERNAL = 9;
public static final int NOTIFY_DOWNLOAD = 10;

public static final String EXTRA_COMMAND = "Command";
private static final String EXTRA_REASON = "Reason";
Expand Down Expand Up @@ -439,6 +441,16 @@ 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 @@ -2898,6 +2910,36 @@ private void showDisabledNotification() {
NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

private void showLockdownNotification() {
Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
PendingIntent pi = PendingIntent.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));

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);
main.putExtra(ActivityMain.EXTRA_APPROVE, true);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<string name="app_description">NetGuard راهکارهای ساده و پیشرفته‌ای برای مسدود کردن دسترسی به اینترنت فراهم می‌کند - بدون نیاز به روت بودن گوشی. هرکدام از برنامه‌ها و سایتها می‌توانند جداگانه به وای‌فای/داده موبایل دسترسی مجاز یا غیر مجاز داشته باشند.</string>
<string name="app_android">NetGuard نیاز به اندروید 5.1 یا بالاتر دارد</string>
<string name="app_xposed">Xposed موجب خطاهای زیاد می‌شود، که شاید موجب حذف شدن NetGuard از گوگل پلی استور شود، برای همین NetGuard هنگامی که Xposed نصب شده است ، پشتیبانی نمی‌شود</string>
<string name="app_privacy"><a href="http://www.cyanogenmod.org/docs/privacy"> سیاست حفظ حریم خصوصی</a></string>
<string name="app_privacy"><a href="https://www.netguard.me/privacy/">Privacy policy</a></string>
<string name="app_first">مراقبتی عالی برای توسعه و آزمایش NetGuard بکار برده شده است، با این حال تضمین اینکه NetGuard بر روی هر دستگاهی به درستی کار خواد کرد غیرممکن است.</string>
<string name="app_agree">می‌پذیرم</string>
<string name="app_disagree">نمی‌پذیرم</string>
Expand Down
Loading