mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-03 05:44:14 +00:00
Android 12 compatibility
This commit is contained in:
parent
a4cfeb6b93
commit
22e04a7a59
2 changed files with 69 additions and 22 deletions
|
@ -193,11 +193,13 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
prefs.edit().putBoolean("enabled", isChecked).apply();
|
prefs.edit().putBoolean("enabled", isChecked).apply();
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
try {
|
||||||
String alwaysOn = Settings.Secure.getString(getContentResolver(), "always_on_vpn_app");
|
String alwaysOn = Settings.Secure.getString(getContentResolver(), "always_on_vpn_app");
|
||||||
Log.i(TAG, "Always-on=" + alwaysOn);
|
Log.i(TAG, "Always-on=" + alwaysOn);
|
||||||
if (!TextUtils.isEmpty(alwaysOn))
|
if (!TextUtils.isEmpty(alwaysOn))
|
||||||
if (getPackageName().equals(alwaysOn)) {
|
if (getPackageName().equals(alwaysOn)) {
|
||||||
if (prefs.getBoolean("filter", false)) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q &&
|
||||||
|
prefs.getBoolean("filter", false)) {
|
||||||
int lockdown = Settings.Secure.getInt(getContentResolver(), "always_on_vpn_lockdown", 0);
|
int lockdown = Settings.Secure.getInt(getContentResolver(), "always_on_vpn_lockdown", 0);
|
||||||
Log.i(TAG, "Lockdown=" + lockdown);
|
Log.i(TAG, "Lockdown=" + lockdown);
|
||||||
if (lockdown != 0) {
|
if (lockdown != 0) {
|
||||||
|
@ -211,6 +213,9 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
Toast.makeText(ActivityMain.this, R.string.msg_always_on, Toast.LENGTH_LONG).show();
|
Toast.makeText(ActivityMain.this, R.string.msg_always_on, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||||
|
}
|
||||||
|
|
||||||
boolean filter = prefs.getBoolean("filter", false);
|
boolean filter = prefs.getBoolean("filter", false);
|
||||||
if (filter && Util.isPrivateDns(ActivityMain.this))
|
if (filter && Util.isPrivateDns(ActivityMain.this))
|
||||||
|
|
|
@ -57,6 +57,7 @@ import android.os.ParcelFileDescriptor;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
|
@ -160,12 +161,13 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
private static final int NOTIFY_ENFORCING = 1;
|
private static final int NOTIFY_ENFORCING = 1;
|
||||||
private static final int NOTIFY_WAITING = 2;
|
private static final int NOTIFY_WAITING = 2;
|
||||||
private static final int NOTIFY_DISABLED = 3;
|
private static final int NOTIFY_DISABLED = 3;
|
||||||
private static final int NOTIFY_AUTOSTART = 4;
|
private static final int NOTIFY_LOCKDOWN = 4;
|
||||||
private static final int NOTIFY_ERROR = 5;
|
private static final int NOTIFY_AUTOSTART = 5;
|
||||||
private static final int NOTIFY_TRAFFIC = 6;
|
private static final int NOTIFY_ERROR = 6;
|
||||||
private static final int NOTIFY_UPDATE = 7;
|
private static final int NOTIFY_TRAFFIC = 7;
|
||||||
public static final int NOTIFY_EXTERNAL = 8;
|
private static final int NOTIFY_UPDATE = 8;
|
||||||
public static final int NOTIFY_DOWNLOAD = 9;
|
public static final int NOTIFY_EXTERNAL = 9;
|
||||||
|
public static final int NOTIFY_DOWNLOAD = 10;
|
||||||
|
|
||||||
public static final String EXTRA_COMMAND = "Command";
|
public static final String EXTRA_COMMAND = "Command";
|
||||||
private static final String EXTRA_REASON = "Reason";
|
private static final String EXTRA_REASON = "Reason";
|
||||||
|
@ -439,6 +441,16 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
Log.e(TAG, "Unknown command=" + cmd);
|
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) {
|
if (cmd == Command.start || cmd == Command.reload || cmd == Command.stop) {
|
||||||
// Update main view
|
// Update main view
|
||||||
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
|
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
|
||||||
|
@ -2898,6 +2910,36 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
|
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() {
|
private void showAutoStartNotification() {
|
||||||
Intent main = new Intent(this, ActivityMain.class);
|
Intent main = new Intent(this, ActivityMain.class);
|
||||||
main.putExtra(ActivityMain.EXTRA_APPROVE, true);
|
main.putExtra(ActivityMain.EXTRA_APPROVE, true);
|
||||||
|
|
Loading…
Reference in a new issue