NetGuard v2.328版本的 MD5 值为:4adaa6f0accf8a6a5ab62c36e5a5d3f8

以下内容为反编译后的 ActivitySettings.java 源代码,内容仅作参考


package eu.faircode.netguard;

import B.b;
import K0.r;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.MultiSelectListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.preference.TwoStatePreference;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.util.Log;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.appcompat.app.ActivityC0095q;
import androidx.appcompat.app.C0091m;
import androidx.appcompat.app.DialogInterfaceC0092n;
import androidx.core.app.C0127j;
import androidx.core.content.f;
import androidx.core.text.d;
import androidx.core.util.e;
import eu.faircode.netguard.DownloadTask;
import eu.faircode.netguard.Util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlSerializer;
import t.C0496d;
public class ActivitySettings extends ActivityC0095q implements SharedPreferences.OnSharedPreferenceChangeListener {
    private static final Intent INTENT_VPN_SETTINGS = new Intent("android.net.vpn.SETTINGS");
    private boolean running = false;
    private DialogInterfaceC0092n dialogFilter = null;
    private BroadcastReceiver interactiveStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Util.logExtras(intent);
            ActivitySettings.this.updateTechnicalInfo();
        }
    };
    private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Util.logExtras(intent);
            ActivitySettings.this.updateTechnicalInfo();
        }
    };

    public class AnonymousClass1 implements Preference.OnPreferenceClickListener {
        AnonymousClass1() {
        }

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() {
                @Override
                public void onSure() {
                    new AsyncTask() {
                        @Override
                        public Throwable doInBackground(Object... objArr) {
                            try {
                                DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1);
                                return null;
                            } catch (Throwable th) {
                                return th;
                            }
                        }

                        @Override
                        public void onPostExecute(Throwable th) {
                            if (th == null) {
                                Toast.makeText(ActivitySettings.this, (int) R.string.msg_completed, 1).show();
                            } else {
                                Toast.makeText(ActivitySettings.this, th.toString(), 1).show();
                            }
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
                }
            });
            return false;
        }
    }

    public class XmlImportHandler extends DefaultHandler {
        private Context context;
        public boolean enabled = false;
        public Map application = new HashMap();
        public Map wifi = new HashMap();
        public Map mobile = new HashMap();
        public Map screen_wifi = new HashMap();
        public Map screen_other = new HashMap();
        public Map roaming = new HashMap();
        public Map lockdown = new HashMap();
        public Map apply = new HashMap();
        public Map notify = new HashMap();
        private Map current = null;

        public XmlImportHandler(Context context) {
            this.context = context;
        }

        private int getUid(String str) {
            if ("root".equals(str)) {
                return 0;
            }
            if ("android.media".equals(str)) {
                return 1013;
            }
            if ("android.multicast".equals(str)) {
                return 1020;
            }
            if ("android.gps".equals(str)) {
                return 1021;
            }
            if ("android.dns".equals(str)) {
                return 1051;
            }
            if ("nobody".equals(str)) {
                return 9999;
            }
            return ActivitySettings.this.getPackageManager().getApplicationInfo(str, 0).uid;
        }

        @Override
        public void startElement(String str, String str2, String str3, Attributes attributes) {
            int parseInt;
            if (!str3.equals("netguard")) {
                if (str3.equals("application")) {
                    this.current = this.application;
                } else if (str3.equals("wifi")) {
                    this.current = this.wifi;
                } else if (str3.equals("mobile")) {
                    this.current = this.mobile;
                } else if (str3.equals("screen_wifi")) {
                    this.current = this.screen_wifi;
                } else if (str3.equals("screen_other")) {
                    this.current = this.screen_other;
                } else if (str3.equals("roaming")) {
                    this.current = this.roaming;
                } else if (str3.equals("lockdown")) {
                    this.current = this.lockdown;
                } else if (str3.equals("apply")) {
                    this.current = this.apply;
                } else if (str3.equals("notify")) {
                    this.current = this.notify;
                } else if (str3.equals("filter")) {
                    this.current = null;
                    Log.i("NetGuard.Settings", "Clearing filters");
                    DatabaseHelper.getInstance(this.context).clearAccess();
                } else if (str3.equals("forward")) {
                    this.current = null;
                    Log.i("NetGuard.Settings", "Clearing forwards");
                    DatabaseHelper.getInstance(this.context).deleteForward();
                } else if (str3.equals("setting")) {
                    String value = attributes.getValue("key");
                    String value2 = attributes.getValue("type");
                    String value3 = attributes.getValue("value");
                    if (this.current == null) {
                        Log.e("NetGuard.Settings", "No current key=" + value);
                    } else if ("enabled".equals(value)) {
                        this.enabled = Boolean.parseBoolean(value3);
                    } else {
                        if (this.current == this.application) {
                            if ("log".equals(value)) {
                                if (!IAB.isPurchased("log", this.context)) {
                                    return;
                                }
                            } else if ("theme".equals(value)) {
                                if (!IAB.isPurchased("theme", this.context)) {
                                    return;
                                }
                            } else if ("show_stats".equals(value) && !IAB.isPurchased("speed", this.context)) {
                                return;
                            }
                            if ("hosts_last_import".equals(value) || "hosts_last_download".equals(value)) {
                                return;
                            }
                        }
                        if ("boolean".equals(value2)) {
                            this.current.put(value, Boolean.valueOf(Boolean.parseBoolean(value3)));
                        } else if ("integer".equals(value2)) {
                            this.current.put(value, Integer.valueOf(Integer.parseInt(value3)));
                        } else if ("string".equals(value2)) {
                            this.current.put(value, value3);
                        } else if ("set".equals(value2)) {
                            HashSet hashSet = new HashSet();
                            if (!TextUtils.isEmpty(value3)) {
                                for (String str4 : value3.split("\n")) {
                                    hashSet.add(str4);
                                }
                            }
                            this.current.put(value, hashSet);
                        } else {
                            Log.e("NetGuard.Settings", "Unknown type key=" + value);
                        }
                    }
                } else if (str3.equals("rule")) {
                    String value4 = attributes.getValue("pkg");
                    String value5 = attributes.getValue("version");
                    String value6 = attributes.getValue("protocol");
                    Packet packet = new Packet();
                    if (value5 == null) {
                        parseInt = 4;
                        int i2 = 6 << 4;
                    } else {
                        parseInt = Integer.parseInt(value5);
                    }
                    packet.version = parseInt;
                    packet.protocol = value6 == null ? 6 : Integer.parseInt(value6);
                    packet.daddr = attributes.getValue("daddr");
                    packet.dport = Integer.parseInt(attributes.getValue("dport"));
                    packet.time = Long.parseLong(attributes.getValue("time"));
                    int parseInt2 = Integer.parseInt(attributes.getValue("block"));
                    try {
                        packet.uid = getUid(value4);
                        DatabaseHelper.getInstance(this.context).updateAccess(packet, null, parseInt2);
                    } catch (PackageManager.NameNotFoundException unused) {
                        Log.w("NetGuard.Settings", "Package not found pkg=" + value4);
                    }
                } else if (str3.equals("port")) {
                    String value7 = attributes.getValue("pkg");
                    try {
                        DatabaseHelper.getInstance(this.context).addForward(Integer.parseInt(attributes.getValue("protocol")), Integer.parseInt(attributes.getValue("dport")), attributes.getValue("raddr"), Integer.parseInt(attributes.getValue("rport")), getUid(value7));
                    } catch (PackageManager.NameNotFoundException unused2) {
                        Log.w("NetGuard.Settings", "Package not found pkg=" + value7);
                    }
                } else {
                    Log.e("NetGuard.Settings", "Unknown element qname=".concat(str3));
                }
            }
        }
    }

    private void checkAddress(String str, boolean z2) {
        if (str != null) {
            str = str.trim();
        }
        if (TextUtils.isEmpty(str)) {
            throw new IllegalArgumentException("Bad address");
        }
        if (!Util.isNumericAddress(str)) {
            throw new IllegalArgumentException("Bad address");
        }
        if (!z2) {
            InetAddress byName = InetAddress.getByName(str);
            if (byName.isLoopbackAddress() || byName.isAnyLocalAddress()) {
                throw new IllegalArgumentException("Bad address");
            }
        }
    }

    private void checkDomain(String str) {
        if (str != null) {
            str = str.trim();
        }
        if (TextUtils.isEmpty(str)) {
            throw new IllegalArgumentException("Bad address");
        }
        if (Util.isNumericAddress(str)) {
            throw new IllegalArgumentException("Bad address");
        }
        if (!e.f1524a.matcher(str).matches()) {
            throw new IllegalArgumentException("Bad address");
        }
    }

    private boolean checkPermissions(String str) {
        PreferenceScreen preferenceScreen = getPreferenceScreen();
        SharedPreferences f = b.f(this);
        if ((str == null || "disable_on_call".equals(str)) && f.getBoolean("disable_on_call", false) && !Util.hasPhoneStatePermission(this)) {
            f.edit().putBoolean("disable_on_call", false).apply();
            ((TwoStatePreference) preferenceScreen.findPreference("disable_on_call")).setChecked(false);
            requestPermissions(new String[]{"android.permission.READ_PHONE_STATE"}, 5);
            if (str != null) {
                return false;
            }
        }
        return true;
    }

    private void filterExport(XmlSerializer xmlSerializer) {
        String str = "block";
        String str2 = "time";
        Cursor access = DatabaseHelper.getInstance(this).getAccess();
        try {
            int columnIndex = access.getColumnIndex("uid");
            int columnIndex2 = access.getColumnIndex("version");
            int columnIndex3 = access.getColumnIndex("protocol");
            int columnIndex4 = access.getColumnIndex("daddr");
            int columnIndex5 = access.getColumnIndex("dport");
            int columnIndex6 = access.getColumnIndex("time");
            int columnIndex7 = access.getColumnIndex("block");
            while (access.moveToNext()) {
                String str3 = str;
                int i2 = columnIndex;
                String[] packages = getPackages(access.getInt(columnIndex));
                int length = packages.length;
                int i3 = columnIndex7;
                int i4 = 0;
                while (i4 < length) {
                    int i5 = length;
                    String str4 = packages[i4];
                    String[] strArr = packages;
                    xmlSerializer.startTag(null, "rule");
                    int i6 = i4;
                    xmlSerializer.attribute(null, "pkg", str4);
                    xmlSerializer.attribute(null, "version", Integer.toString(access.getInt(columnIndex2)));
                    xmlSerializer.attribute(null, "protocol", Integer.toString(access.getInt(columnIndex3)));
                    xmlSerializer.attribute(null, "daddr", access.getString(columnIndex4));
                    xmlSerializer.attribute(null, "dport", Integer.toString(access.getInt(columnIndex5)));
                    xmlSerializer.attribute(null, str2, Long.toString(access.getLong(columnIndex6)));
                    int i7 = i3;
                    String str5 = str2;
                    String str6 = str3;
                    xmlSerializer.attribute(null, str6, Integer.toString(access.getInt(i7)));
                    xmlSerializer.endTag(null, "rule");
                    i4 = i6 + 1;
                    str3 = str6;
                    str2 = str5;
                    packages = strArr;
                    i3 = i7;
                    length = i5;
                }
                columnIndex7 = i3;
                str = str3;
                columnIndex = i2;
            }
            access.close();
        } catch (Throwable th) {
            if (access != null) {
                try {
                    access.close();
                } catch (Throwable th2) {
                    th.addSuppressed(th2);
                }
            }
            throw th;
        }
    }

    private void forwardExport(XmlSerializer xmlSerializer) {
        Cursor forwarding = DatabaseHelper.getInstance(this).getForwarding();
        try {
            int columnIndex = forwarding.getColumnIndex("protocol");
            int columnIndex2 = forwarding.getColumnIndex("dport");
            int columnIndex3 = forwarding.getColumnIndex("raddr");
            int columnIndex4 = forwarding.getColumnIndex("rport");
            int columnIndex5 = forwarding.getColumnIndex("ruid");
            while (forwarding.moveToNext()) {
                String[] packages = getPackages(forwarding.getInt(columnIndex5));
                int length = packages.length;
                int i2 = 0;
                while (i2 < length) {
                    int i3 = columnIndex5;
                    String str = packages[i2];
                    String[] strArr = packages;
                    xmlSerializer.startTag(null, "port");
                    xmlSerializer.attribute(null, "pkg", str);
                    xmlSerializer.attribute(null, "protocol", Integer.toString(forwarding.getInt(columnIndex)));
                    xmlSerializer.attribute(null, "dport", Integer.toString(forwarding.getInt(columnIndex2)));
                    xmlSerializer.attribute(null, "raddr", forwarding.getString(columnIndex3));
                    xmlSerializer.attribute(null, "rport", Integer.toString(forwarding.getInt(columnIndex4)));
                    xmlSerializer.endTag(null, "port");
                    i2++;
                    columnIndex5 = i3;
                    packages = strArr;
                }
            }
            forwarding.close();
        } catch (Throwable th) {
            if (forwarding != null) {
                try {
                    forwarding.close();
                } catch (Throwable th2) {
                    th.addSuppressed(th2);
                }
            }
            throw th;
        }
    }

    public Intent getIntentCreateExport() {
        Intent intent = new Intent("android.intent.action.CREATE_DOCUMENT");
        intent.addCategory("android.intent.category.OPENABLE");
        intent.setType("*/*");
        intent.putExtra("android.intent.extra.TITLE", "netguard_" + new SimpleDateFormat("yyyyMMdd").format(Long.valueOf(new Date().getTime())) + ".xml");
        return intent;
    }

    public Intent getIntentOpenExport() {
        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
        intent.addCategory("android.intent.category.OPENABLE");
        intent.setType("*/*");
        return intent;
    }

    public Intent getIntentOpenHosts() {
        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
        intent.addCategory("android.intent.category.OPENABLE");
        intent.setType("*/*");
        return intent;
    }

    private String[] getPackages(int i2) {
        if (i2 == 0) {
            return new String[]{"root"};
        }
        if (i2 == 1013) {
            return new String[]{"mediaserver"};
        }
        if (i2 == 9999) {
            return new String[]{"nobody"};
        }
        String[] packagesForUid = getPackageManager().getPackagesForUid(i2);
        if (packagesForUid == null) {
            packagesForUid = new String[0];
        }
        return packagesForUid;
    }

    public PreferenceScreen getPreferenceScreen() {
        return ((PreferenceFragment) getFragmentManager().findFragmentById(16908290)).getPreferenceScreen();
    }

    private void handleExport(final Intent intent) {
        new AsyncTask() {
            @Override
            public Throwable doInBackground(Object... objArr) {
                Throwable th;
                OutputStream outputStream;
                try {
                    Uri data = intent.getData();
                    if (intent.hasExtra("org.openintents.extra.DIR_PATH")) {
                        data = Uri.parse(data + "/netguard_" + new SimpleDateFormat("yyyyMMdd").format(Long.valueOf(new Date().getTime())) + ".xml");
                    }
                    Log.i("NetGuard.Settings", "Writing URI=" + data);
                    outputStream = ActivitySettings.this.getContentResolver().openOutputStream(data);
                    try {
                        ActivitySettings.this.xmlExport(outputStream);
                        if (outputStream != null) {
                            try {
                                outputStream.close();
                            } catch (IOException e2) {
                                r.f(e2, new StringBuilder(), "\n", e2, "NetGuard.Settings");
                            }
                        }
                        return null;
                    } catch (Throwable th2) {
                        th = th2;
                        try {
                            Log.e("NetGuard.Settings", th.toString() + "\n" + Log.getStackTraceString(th));
                            if (outputStream != null) {
                                try {
                                    outputStream.close();
                                } catch (IOException e3) {
                                    r.f(e3, new StringBuilder(), "\n", e3, "NetGuard.Settings");
                                }
                            }
                            return th;
                        } catch (Throwable th3) {
                            if (outputStream != null) {
                                try {
                                    outputStream.close();
                                } catch (IOException e4) {
                                    r.f(e4, new StringBuilder(), "\n", e4, "NetGuard.Settings");
                                }
                            }
                            throw th3;
                        }
                    }
                } catch (Throwable th4) {
                    th = th4;
                    outputStream = null;
                }
            }

            @Override
            public void onPostExecute(Throwable th) {
                if (ActivitySettings.this.running) {
                    if (th == null) {
                        Toast.makeText(ActivitySettings.this, (int) R.string.msg_completed, 1).show();
                    } else {
                        Toast.makeText(ActivitySettings.this, th.toString(), 1).show();
                    }
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
    }

    private void handleHosts(final Intent intent, final boolean z2) {
        new AsyncTask() {
            @Override
            public Throwable doInBackground(Object... objArr) {
                Throwable th;
                FileOutputStream fileOutputStream;
                String str = "*/*";
                File file = new File(ActivitySettings.this.getFilesDir(), "hosts.txt");
                FileInputStream fileInputStream = null;
                try {
                    Log.i("NetGuard.Settings", "Reading URI=" + intent.getData());
                    ContentResolver contentResolver = ActivitySettings.this.getContentResolver();
                    String[] streamTypes = contentResolver.getStreamTypes(intent.getData(), "*/*");
                    if (streamTypes != null && streamTypes.length != 0) {
                        str = streamTypes[0];
                    }
                    FileInputStream createInputStream = contentResolver.openTypedAssetFileDescriptor(intent.getData(), str, null).createInputStream();
                    try {
                        fileOutputStream = new FileOutputStream(file, z2);
                        try {
                            byte[] bArr = new byte[4096];
                            long j2 = 0;
                            while (true) {
                                int read = createInputStream.read(bArr);
                                if (read <= 0) {
                                    break;
                                }
                                fileOutputStream.write(bArr, 0, read);
                                j2 += read;
                            }
                            Log.i("NetGuard.Settings", "Copied bytes=" + j2);
                            try {
                                fileOutputStream.close();
                            } catch (IOException e2) {
                                r.f(e2, new StringBuilder(), "\n", e2, "NetGuard.Settings");
                            }
                            try {
                                createInputStream.close();
                            } catch (IOException e3) {
                                r.f(e3, new StringBuilder(), "\n", e3, "NetGuard.Settings");
                            }
                            return null;
                        } catch (Throwable th2) {
                            th = th2;
                            fileInputStream = createInputStream;
                            try {
                                Log.e("NetGuard.Settings", th.toString() + "\n" + Log.getStackTraceString(th));
                                if (fileOutputStream != null) {
                                    try {
                                        fileOutputStream.close();
                                    } catch (IOException e4) {
                                        r.f(e4, new StringBuilder(), "\n", e4, "NetGuard.Settings");
                                    }
                                }
                                if (fileInputStream != null) {
                                    try {
                                        fileInputStream.close();
                                    } catch (IOException e5) {
                                        r.f(e5, new StringBuilder(), "\n", e5, "NetGuard.Settings");
                                    }
                                }
                                return th;
                            } catch (Throwable th3) {
                                if (fileOutputStream != null) {
                                    try {
                                        fileOutputStream.close();
                                    } catch (IOException e6) {
                                        r.f(e6, new StringBuilder(), "\n", e6, "NetGuard.Settings");
                                    }
                                }
                                if (fileInputStream != null) {
                                    try {
                                        fileInputStream.close();
                                    } catch (IOException e7) {
                                        r.f(e7, new StringBuilder(), "\n", e7, "NetGuard.Settings");
                                    }
                                }
                                throw th3;
                            }
                        }
                    } catch (Throwable th4) {
                        th = th4;
                        fileOutputStream = null;
                    }
                } catch (Throwable th5) {
                    th = th5;
                    fileOutputStream = null;
                }
            }

            @Override
            public void onPostExecute(Throwable th) {
                if (ActivitySettings.this.running) {
                    if (th != null) {
                        Toast.makeText(ActivitySettings.this, th.toString(), 1).show();
                        return;
                    }
                    SharedPreferences f = b.f(ActivitySettings.this);
                    String format = DateFormat.getDateTimeInstance().format(Long.valueOf(new Date().getTime()));
                    f.edit().putString("hosts_last_import", format).apply();
                    if (ActivitySettings.this.running) {
                        ActivitySettings.this.getPreferenceScreen().findPreference("hosts_import").setSummary(ActivitySettings.this.getString(R.string.msg_import_last, format));
                        Toast.makeText(ActivitySettings.this, (int) R.string.msg_completed, 1).show();
                    }
                    ServiceSinkhole.reload("hosts import", ActivitySettings.this, false);
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
    }

    private void handleImport(final Intent intent) {
        new AsyncTask() {
            @Override
            public Throwable doInBackground(Object... objArr) {
                Throwable th;
                String str = "*/*";
                FileInputStream fileInputStream = null;
                try {
                    Log.i("NetGuard.Settings", "Reading URI=" + intent.getData());
                    ContentResolver contentResolver = ActivitySettings.this.getContentResolver();
                    String[] streamTypes = contentResolver.getStreamTypes(intent.getData(), "*/*");
                    if (streamTypes != null && streamTypes.length != 0) {
                        str = streamTypes[0];
                    }
                    FileInputStream createInputStream = contentResolver.openTypedAssetFileDescriptor(intent.getData(), str, null).createInputStream();
                    try {
                        ActivitySettings.this.xmlImport(createInputStream);
                        if (createInputStream != null) {
                            try {
                                createInputStream.close();
                            } catch (IOException e2) {
                                r.f(e2, new StringBuilder(), "\n", e2, "NetGuard.Settings");
                            }
                        }
                        return null;
                    } catch (Throwable th2) {
                        th = th2;
                        fileInputStream = createInputStream;
                        try {
                            Log.e("NetGuard.Settings", th.toString() + "\n" + Log.getStackTraceString(th));
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e3) {
                                    r.f(e3, new StringBuilder(), "\n", e3, "NetGuard.Settings");
                                }
                            }
                            return th;
                        } catch (Throwable th3) {
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e4) {
                                    r.f(e4, new StringBuilder(), "\n", e4, "NetGuard.Settings");
                                }
                            }
                            throw th3;
                        }
                    }
                } catch (Throwable th4) {
                    th = th4;
                }
            }

            @Override
            public void onPostExecute(Throwable th) {
                if (ActivitySettings.this.running) {
                    if (th != null) {
                        Toast.makeText(ActivitySettings.this, th.toString(), 1).show();
                        return;
                    }
                    Toast.makeText(ActivitySettings.this, (int) R.string.msg_completed, 1).show();
                    ServiceSinkhole.reloadStats("import", ActivitySettings.this);
                    ActivitySettings.this.recreate();
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
    }

    private void markPro(Preference preference, String str) {
        if (str == null || !IAB.isPurchased(str, this)) {
            boolean z2 = b.f(this).getBoolean("dark_theme", false);
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("  " + ((Object) preference.getTitle()));
            spannableStringBuilder.setSpan(new ImageSpan(this, z2 ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, 33);
            preference.setTitle(spannableStringBuilder);
        }
    }

    public void updateTechnicalInfo() {
        PreferenceScreen preferenceScreen = getPreferenceScreen();
        Preference findPreference = preferenceScreen.findPreference("technical_info");
        Preference findPreference2 = preferenceScreen.findPreference("technical_network");
        findPreference.setSummary(Util.getGeneralInfo(this));
        findPreference2.setSummary(Util.getNetworkInfo(this));
    }

    private void xmlExport(SharedPreferences sharedPreferences, XmlSerializer xmlSerializer) {
        Map<String, ?> all = sharedPreferences.getAll();
        for (String str : all.keySet()) {
            Object obj = all.get(str);
            if (!"imported".equals(str)) {
                if (obj instanceof Boolean) {
                    xmlSerializer.startTag(null, "setting");
                    xmlSerializer.attribute(null, "key", str);
                    xmlSerializer.attribute(null, "type", "boolean");
                    xmlSerializer.attribute(null, "value", obj.toString());
                    xmlSerializer.endTag(null, "setting");
                } else if (obj instanceof Integer) {
                    xmlSerializer.startTag(null, "setting");
                    xmlSerializer.attribute(null, "key", str);
                    xmlSerializer.attribute(null, "type", "integer");
                    xmlSerializer.attribute(null, "value", obj.toString());
                    xmlSerializer.endTag(null, "setting");
                } else if (obj instanceof String) {
                    xmlSerializer.startTag(null, "setting");
                    xmlSerializer.attribute(null, "key", str);
                    xmlSerializer.attribute(null, "type", "string");
                    xmlSerializer.attribute(null, "value", obj.toString());
                    xmlSerializer.endTag(null, "setting");
                } else if (obj instanceof Set) {
                    xmlSerializer.startTag(null, "setting");
                    xmlSerializer.attribute(null, "key", str);
                    xmlSerializer.attribute(null, "type", "set");
                    xmlSerializer.attribute(null, "value", TextUtils.join("\n", (Set) obj));
                    xmlSerializer.endTag(null, "setting");
                } else {
                    Log.e("NetGuard.Settings", "Unknown key=" + str);
                }
            }
        }
    }

    public void xmlExport(OutputStream outputStream) {
        XmlSerializer newSerializer = Xml.newSerializer();
        newSerializer.setOutput(outputStream, "UTF-8");
        newSerializer.startDocument(null, Boolean.TRUE);
        newSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        newSerializer.startTag(null, "netguard");
        newSerializer.startTag(null, "application");
        xmlExport(b.f(this), newSerializer);
        newSerializer.endTag(null, "application");
        newSerializer.startTag(null, "wifi");
        xmlExport(getSharedPreferences("wifi", 0), newSerializer);
        newSerializer.endTag(null, "wifi");
        newSerializer.startTag(null, "mobile");
        xmlExport(getSharedPreferences("other", 0), newSerializer);
        newSerializer.endTag(null, "mobile");
        newSerializer.startTag(null, "screen_wifi");
        xmlExport(getSharedPreferences("screen_wifi", 0), newSerializer);
        newSerializer.endTag(null, "screen_wifi");
        newSerializer.startTag(null, "screen_other");
        xmlExport(getSharedPreferences("screen_other", 0), newSerializer);
        newSerializer.endTag(null, "screen_other");
        newSerializer.startTag(null, "roaming");
        xmlExport(getSharedPreferences("roaming", 0), newSerializer);
        newSerializer.endTag(null, "roaming");
        newSerializer.startTag(null, "lockdown");
        xmlExport(getSharedPreferences("lockdown", 0), newSerializer);
        newSerializer.endTag(null, "lockdown");
        newSerializer.startTag(null, "apply");
        xmlExport(getSharedPreferences("apply", 0), newSerializer);
        newSerializer.endTag(null, "apply");
        newSerializer.startTag(null, "notify");
        xmlExport(getSharedPreferences("notify", 0), newSerializer);
        newSerializer.endTag(null, "notify");
        newSerializer.startTag(null, "filter");
        filterExport(newSerializer);
        newSerializer.endTag(null, "filter");
        newSerializer.startTag(null, "forward");
        forwardExport(newSerializer);
        newSerializer.endTag(null, "forward");
        newSerializer.endTag(null, "netguard");
        newSerializer.endDocument();
        newSerializer.flush();
    }

    public void xmlImport(InputStream inputStream) {
        SharedPreferences f = b.f(this);
        f.unregisterOnSharedPreferenceChangeListener(this);
        f.edit().putBoolean("enabled", false).apply();
        ServiceSinkhole.stop("import", this, false);
        XMLReader xMLReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
        XmlImportHandler xmlImportHandler = new XmlImportHandler(this);
        xMLReader.setContentHandler(xmlImportHandler);
        xMLReader.parse(new InputSource(inputStream));
        xmlImport(xmlImportHandler.application, f);
        xmlImport(xmlImportHandler.wifi, getSharedPreferences("wifi", 0));
        xmlImport(xmlImportHandler.mobile, getSharedPreferences("other", 0));
        xmlImport(xmlImportHandler.screen_wifi, getSharedPreferences("screen_wifi", 0));
        xmlImport(xmlImportHandler.screen_other, getSharedPreferences("screen_other", 0));
        xmlImport(xmlImportHandler.roaming, getSharedPreferences("roaming", 0));
        xmlImport(xmlImportHandler.lockdown, getSharedPreferences("lockdown", 0));
        xmlImport(xmlImportHandler.apply, getSharedPreferences("apply", 0));
        xmlImport(xmlImportHandler.notify, getSharedPreferences("notify", 0));
        ReceiverAutostart.upgrade(true, this);
        DatabaseHelper.clearCache();
        f.edit().putBoolean("imported", true).apply();
        f.registerOnSharedPreferenceChangeListener(this);
    }

    private void xmlImport(Map map, SharedPreferences sharedPreferences) {
        SharedPreferences.Editor edit = sharedPreferences.edit();
        for (String str : sharedPreferences.getAll().keySet()) {
            if (!"enabled".equals(str)) {
                edit.remove(str);
            }
        }
        for (String str2 : map.keySet()) {
            Object obj = map.get(str2);
            if (obj instanceof Boolean) {
                edit.putBoolean(str2, ((Boolean) obj).booleanValue());
            } else if (obj instanceof Integer) {
                edit.putInt(str2, ((Integer) obj).intValue());
            } else if (obj instanceof String) {
                edit.putString(str2, (String) obj);
            } else if (obj instanceof Set) {
                edit.putStringSet(str2, (Set) obj);
            } else {
                Log.e("NetGuard.Settings", "Unknown type=" + obj.getClass());
            }
        }
        edit.apply();
    }

    @Override
    protected void onActivityResult(int i2, int i3, Intent intent) {
        StringBuilder sb = new StringBuilder("onActivityResult request=");
        sb.append(i2);
        sb.append(" result=");
        sb.append(i2);
        sb.append(" ok=");
        sb.append(i3 == -1);
        Log.i("NetGuard.Settings", sb.toString());
        if (i2 == 1) {
            if (i3 != -1 || intent == null) {
                return;
            }
            handleExport(intent);
        } else if (i2 == 2) {
            if (i3 != -1 || intent == null) {
                return;
            }
            handleImport(intent);
        } else if (i2 == 3) {
            if (i3 != -1 || intent == null) {
                return;
            }
            handleHosts(intent, false);
        } else if (i2 == 4) {
            if (i3 != -1 || intent == null) {
                return;
            }
            handleHosts(intent, true);
        } else {
            Log.w("NetGuard.Settings", "Unknown activity result request=" + i2);
            super.onActivityResult(i2, i3, intent);
        }
    }

    @Override
    protected void onCreate(Bundle bundle) {
        Util.setTheme(this);
        super.onCreate(bundle);
        getFragmentManager().beginTransaction().replace(16908290, new FragmentSettings()).commit();
        getSupportActionBar().e(R.string.menu_settings);
        this.running = true;
    }

    @Override
    protected void onDestroy() {
        this.running = false;
        DialogInterfaceC0092n dialogInterfaceC0092n = this.dialogFilter;
        if (dialogInterfaceC0092n != null) {
            dialogInterfaceC0092n.dismiss();
            boolean z2 = true | false;
            this.dialogFilter = null;
        }
        super.onDestroy();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        Log.i("NetGuard.Settings", "Up");
        C0127j.e(this);
        return true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        b.f(this).unregisterOnSharedPreferenceChangeListener(this);
        unregisterReceiver(this.interactiveStateReceiver);
        unregisterReceiver(this.connectivityChangedReceiver);
    }

    @Override
    protected void onPostCreate(Bundle bundle) {
        boolean z2;
        char c2;
        super.onPostCreate(bundle);
        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        final SharedPreferences f = b.f(this);
        PreferenceGroup preferenceGroup = (PreferenceGroup) ((PreferenceGroup) preferenceScreen.findPreference("screen_options")).findPreference("category_options");
        PreferenceGroup preferenceGroup2 = (PreferenceGroup) ((PreferenceGroup) preferenceScreen.findPreference("screen_network_options")).findPreference("category_network_options");
        PreferenceGroup preferenceGroup3 = (PreferenceGroup) ((PreferenceGroup) preferenceScreen.findPreference("screen_advanced_options")).findPreference("category_advanced_options");
        PreferenceGroup preferenceGroup4 = (PreferenceGroup) ((PreferenceGroup) preferenceScreen.findPreference("screen_stats")).findPreference("category_stats");
        PreferenceGroup preferenceGroup5 = (PreferenceGroup) ((PreferenceGroup) preferenceScreen.findPreference("screen_backup")).findPreference("category_backup");
        preferenceScreen.findPreference("auto_enable").setTitle(getString(R.string.setting_auto, f.getString("auto_enable", "0")));
        preferenceScreen.findPreference("screen_delay").setTitle(getString(R.string.setting_delay, f.getString("screen_delay", "0")));
        Preference findPreference = preferenceScreen.findPreference("theme");
        String string = f.getString("theme", "teal");
        String[] stringArray = getResources().getStringArray(R.array.themeNames);
        String[] stringArray2 = getResources().getStringArray(R.array.themeValues);
        int i2 = 0;
        while (true) {
            if (i2 >= stringArray.length) {
                break;
            } else if (string.equals(stringArray2[i2])) {
                findPreference.setTitle(getString(R.string.setting_theme, stringArray[i2]));
                break;
            } else {
                i2++;
            }
        }
        MultiSelectListPreference multiSelectListPreference = (MultiSelectListPreference) preferenceScreen.findPreference("wifi_homes");
        if (Build.VERSION.SDK_INT >= 27) {
            preferenceGroup2.removePreference(multiSelectListPreference);
        } else {
            Set<String> stringSet = f.getStringSet("wifi_homes", new HashSet());
            if (stringSet.size() > 0) {
                multiSelectListPreference.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", stringSet)));
            } else {
                multiSelectListPreference.setTitle(getString(R.string.setting_wifi_home, "-"));
            }
            ArrayList arrayList = new ArrayList();
            List<WifiConfiguration> configuredNetworks = ((WifiManager) getApplicationContext().getSystemService("wifi")).getConfiguredNetworks();
            if (configuredNetworks != null) {
                for (WifiConfiguration wifiConfiguration : configuredNetworks) {
                    String str = wifiConfiguration.SSID;
                    if (str == null) {
                        str = "NULL";
                    }
                    arrayList.add(str);
                }
            }
            for (String str2 : stringSet) {
                if (!arrayList.contains(str2)) {
                    arrayList.add(str2);
                }
            }
            multiSelectListPreference.setEntries((CharSequence[]) arrayList.toArray(new CharSequence[0]));
            multiSelectListPreference.setEntryValues((CharSequence[]) arrayList.toArray(new CharSequence[0]));
        }
        int i3 = Build.VERSION.SDK_INT;
        if (i3 >= 30) {
            preferenceGroup3.removePreference((TwoStatePreference) preferenceScreen.findPreference("handover"));
        }
        preferenceScreen.findPreference("reset_usage").setOnPreferenceClickListener(new AnonymousClass1());
        if (i3 >= 26) {
            TwoStatePreference twoStatePreference = (TwoStatePreference) preferenceScreen.findPreference("reload_onconnectivity");
            twoStatePreference.setChecked(true);
            twoStatePreference.setEnabled(false);
        }
        Preference findPreference2 = preferenceScreen.findPreference("forwarding");
        findPreference2.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                ActivitySettings.this.startActivity(new Intent(ActivitySettings.this, ActivityForwarding.class));
                boolean z3 = true | true;
                return true;
            }
        });
        boolean canFilter = Util.canFilter(this);
        TwoStatePreference twoStatePreference2 = (TwoStatePreference) preferenceScreen.findPreference("log_app");
        TwoStatePreference twoStatePreference3 = (TwoStatePreference) preferenceScreen.findPreference("filter");
        twoStatePreference2.setEnabled(canFilter);
        twoStatePreference3.setEnabled(canFilter);
        if (!canFilter) {
            twoStatePreference2.setSummary(R.string.msg_unavailable);
            twoStatePreference3.setSummary(R.string.msg_unavailable);
        }
        preferenceScreen.findPreference("vpn4").setTitle(getString(R.string.setting_vpn4, f.getString("vpn4", "10.1.10.1")));
        preferenceScreen.findPreference("vpn6").setTitle(getString(R.string.setting_vpn6, f.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")));
        ((EditTextPreference) preferenceScreen.findPreference("dns")).setTitle(getString(R.string.setting_dns, f.getString("dns", "-")));
        ((EditTextPreference) preferenceScreen.findPreference("dns2")).setTitle(getString(R.string.setting_dns, f.getString("dns2", "-")));
        ((EditTextPreference) preferenceScreen.findPreference("validate")).setTitle(getString(R.string.setting_validate, f.getString("validate", "www.google.com")));
        ((EditTextPreference) preferenceScreen.findPreference("ttl")).setTitle(getString(R.string.setting_ttl, f.getString("ttl", "259200")));
        preferenceScreen.findPreference("socks5_addr").setTitle(getString(R.string.setting_socks5_addr, f.getString("socks5_addr", "-")));
        preferenceScreen.findPreference("socks5_port").setTitle(getString(R.string.setting_socks5_port, f.getString("socks5_port", "-")));
        preferenceScreen.findPreference("socks5_username").setTitle(getString(R.string.setting_socks5_username, f.getString("socks5_username", "-")));
        Preference findPreference3 = preferenceScreen.findPreference("socks5_password");
        Object[] objArr = new Object[1];
        objArr[0] = TextUtils.isEmpty(f.getString("socks5_username", "")) ? "-" : "*****";
        findPreference3.setTitle(getString(R.string.setting_socks5_password, objArr));
        preferenceScreen.findPreference("pcap_record_size").setTitle(getString(R.string.setting_pcap_record_size, f.getString("pcap_record_size", "64")));
        preferenceScreen.findPreference("pcap_file_size").setTitle(getString(R.string.setting_pcap_file_size, f.getString("pcap_file_size", "2")));
        preferenceScreen.findPreference("watchdog").setTitle(getString(R.string.setting_watchdog, f.getString("watchdog", "0")));
        Preference findPreference4 = preferenceScreen.findPreference("show_resolved");
        if (Util.isPlayStoreInstall(this)) {
            preferenceGroup3.removePreference(findPreference4);
        } else {
            findPreference4.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    ActivitySettings.this.startActivity(new Intent(ActivitySettings.this, ActivityDns.class));
                    return true;
                }
            });
        }
        if (i3 >= 24) {
            preferenceGroup4.removePreference(preferenceScreen.findPreference("show_top"));
        }
        ((EditTextPreference) preferenceScreen.findPreference("stats_frequency")).setTitle(getString(R.string.setting_stats_frequency, f.getString("stats_frequency", "1000")));
        ((EditTextPreference) preferenceScreen.findPreference("stats_samples")).setTitle(getString(R.string.setting_stats_samples, f.getString("stats_samples", "90")));
        Preference findPreference5 = preferenceScreen.findPreference("export");
        findPreference5.setEnabled(getIntentCreateExport().resolveActivity(getPackageManager()) != null);
        findPreference5.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                ActivitySettings activitySettings = ActivitySettings.this;
                activitySettings.startActivityForResult(activitySettings.getIntentCreateExport(), 1);
                return true;
            }
        });
        Preference findPreference6 = preferenceScreen.findPreference("import");
        findPreference6.setEnabled(getIntentOpenExport().resolveActivity(getPackageManager()) != null);
        findPreference6.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                ActivitySettings activitySettings = ActivitySettings.this;
                activitySettings.startActivityForResult(activitySettings.getIntentOpenExport(), 2);
                return true;
            }
        });
        Preference findPreference7 = preferenceScreen.findPreference("use_hosts");
        EditTextPreference editTextPreference = (EditTextPreference) preferenceScreen.findPreference("rcode");
        Preference findPreference8 = preferenceScreen.findPreference("hosts_import");
        Preference findPreference9 = preferenceScreen.findPreference("hosts_import_append");
        EditTextPreference editTextPreference2 = (EditTextPreference) preferenceScreen.findPreference("hosts_url");
        final Preference findPreference10 = preferenceScreen.findPreference("hosts_download");
        editTextPreference.setTitle(getString(R.string.setting_rcode, f.getString("rcode", "3")));
        if (Util.isPlayStoreInstall(this) || !Util.hasValidFingerprint(this)) {
            preferenceGroup.removePreference(preferenceScreen.findPreference("update_check"));
        }
        if (Util.isPlayStoreInstall(this)) {
            Log.i("NetGuard.Settings", "Play store install");
            preferenceGroup3.removePreference(findPreference7);
            preferenceGroup3.removePreference(editTextPreference);
            preferenceGroup3.removePreference(findPreference2);
            preferenceGroup5.removePreference(findPreference8);
            preferenceGroup5.removePreference(findPreference9);
            preferenceGroup5.removePreference(editTextPreference2);
            preferenceGroup5.removePreference(findPreference10);
            z2 = true;
        } else {
            String string2 = f.getString("hosts_last_import", null);
            String string3 = f.getString("hosts_last_download", null);
            z2 = true;
            if (string2 != null) {
                c2 = 0;
                findPreference8.setSummary(getString(R.string.msg_import_last, string2));
            } else {
                c2 = 0;
            }
            if (string3 != null) {
                Object[] objArr2 = new Object[1];
                objArr2[c2] = string3;
                findPreference10.setSummary(getString(R.string.msg_download_last, objArr2));
            }
            findPreference8.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null);
            findPreference8.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    ActivitySettings activitySettings = ActivitySettings.this;
                    activitySettings.startActivityForResult(activitySettings.getIntentOpenHosts(), 3);
                    return true;
                }
            });
            findPreference9.setEnabled(findPreference8.isEnabled());
            findPreference9.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    ActivitySettings activitySettings = ActivitySettings.this;
                    activitySettings.startActivityForResult(activitySettings.getIntentOpenHosts(), 4);
                    return true;
                }
            });
            editTextPreference2.setSummary(editTextPreference2.getText());
            findPreference10.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    final File file = new File(ActivitySettings.this.getFilesDir(), "hosts.tmp");
                    final File file2 = new File(ActivitySettings.this.getFilesDir(), "hosts.txt");
                    String text = ((EditTextPreference) preferenceScreen.findPreference("hosts_url")).getText();
                    if ("https://www.netguard.me/hosts".equals(text)) {
                        text = "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts";
                    }
                    try {
                        new DownloadTask(ActivitySettings.this, new URL(text), file, new DownloadTask.Listener() {
                            @Override
                            public void onCancelled() {
                                if (file.exists()) {
                                    file.delete();
                                }
                            }

                            @Override
                            public void onCompleted() {
                                if (file2.exists()) {
                                    file2.delete();
                                }
                                file.renameTo(file2);
                                String format = DateFormat.getDateTimeInstance().format(Long.valueOf(new Date().getTime()));
                                f.edit().putString("hosts_last_download", format).apply();
                                if (ActivitySettings.this.running) {
                                    AnonymousClass8 anonymousClass8 = AnonymousClass8.this;
                                    findPreference10.setSummary(ActivitySettings.this.getString(R.string.msg_download_last, format));
                                    Toast.makeText(ActivitySettings.this, (int) R.string.msg_downloaded, 1).show();
                                }
                                ServiceSinkhole.reload("hosts file download", ActivitySettings.this, false);
                            }

                            @Override
                            public void onException(Throwable th) {
                                if (file.exists()) {
                                    file.delete();
                                }
                                if (ActivitySettings.this.running) {
                                    Toast.makeText(ActivitySettings.this, th.getMessage(), 1).show();
                                }
                            }
                        }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
                    } catch (MalformedURLException e2) {
                        Toast.makeText(ActivitySettings.this, e2.toString(), 1).show();
                    }
                    return true;
                }
            });
        }
        if (!Util.isDebuggable(this)) {
            preferenceScreen.removePreference(preferenceScreen.findPreference("screen_development"));
        }
        Preference.OnPreferenceClickListener onPreferenceClickListener = new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                ActivitySettings.this.updateTechnicalInfo();
                return true;
            }
        };
        Preference findPreference11 = preferenceScreen.findPreference("technical_info");
        Preference findPreference12 = preferenceScreen.findPreference("technical_network");
        Intent intent = INTENT_VPN_SETTINGS;
        if (intent.resolveActivity(getPackageManager()) == null) {
            z2 = false;
        }
        findPreference11.setEnabled(z2);
        findPreference11.setIntent(intent);
        findPreference11.setOnPreferenceClickListener(onPreferenceClickListener);
        findPreference12.setOnPreferenceClickListener(onPreferenceClickListener);
        updateTechnicalInfo();
        markPro(preferenceScreen.findPreference("theme"), "theme");
        markPro(preferenceScreen.findPreference("install"), "notify");
        markPro(preferenceScreen.findPreference("show_stats"), "speed");
    }

    @Override
    public void onRequestPermissionsResult(int i2, String[] strArr, int[] iArr) {
        PreferenceScreen preferenceScreen = getPreferenceScreen();
        SharedPreferences f = b.f(this);
        boolean z2 = iArr.length > 0 && iArr[0] == 0;
        if (i2 == 5) {
            f.edit().putBoolean("disable_on_call", z2).apply();
            ((TwoStatePreference) preferenceScreen.findPreference("disable_on_call")).setChecked(z2);
        }
        if (z2) {
            ServiceSinkhole.reload("permission granted", this, false);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        checkPermissions(null);
        b.f(this).registerOnSharedPreferenceChangeListener(this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.SCREEN_ON");
        intentFilter.addAction("android.intent.action.SCREEN_OFF");
        f.e(this, this.interactiveStateReceiver, intentFilter);
        IntentFilter intentFilter2 = new IntentFilter();
        intentFilter2.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        f.e(this, this.connectivityChangedReceiver, intentFilter2);
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
        if ("theme".equals(str)) {
            if (!"teal".equals(sharedPreferences.getString(str, "teal")) && !IAB.isPurchased("theme", this)) {
                sharedPreferences.edit().putString(str, "teal").apply();
                ((ListPreference) getPreferenceScreen().findPreference(str)).setValue("teal");
                startActivity(new Intent(this, ActivityPro.class));
                return;
            }
        } else if ("install".equals(str)) {
            if (sharedPreferences.getBoolean(str, false) && !IAB.isPurchased("notify", this)) {
                d.d(sharedPreferences, str, false);
                ((TwoStatePreference) getPreferenceScreen().findPreference(str)).setChecked(false);
                startActivity(new Intent(this, ActivityPro.class));
                return;
            }
        } else if ("show_stats".equals(str)) {
            if (sharedPreferences.getBoolean(str, false) && !IAB.isPurchased("speed", this)) {
                sharedPreferences.edit().putBoolean(str, false).apply();
                startActivity(new Intent(this, ActivityPro.class));
                return;
            }
            ((TwoStatePreference) getPreferenceScreen().findPreference(str)).setChecked(sharedPreferences.getBoolean(str, false));
        }
        Object obj = sharedPreferences.getAll().get(str);
        if ((obj instanceof String) && "".equals(obj)) {
            sharedPreferences.edit().remove(str).apply();
        }
        if ("screen_on".equals(str)) {
            d.f("changed ", str, this, false);
            return;
        }
        if (!"whitelist_wifi".equals(str) && !"screen_wifi".equals(str)) {
            if ("whitelist_other".equals(str) || "screen_other".equals(str)) {
                d.f("changed ", str, this, false);
                return;
            } else if ("whitelist_roaming".equals(str)) {
                d.f("changed ", str, this, false);
                return;
            } else if ("auto_enable".equals(str)) {
                getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_auto, sharedPreferences.getString(str, "0")));
                return;
            } else if ("screen_delay".equals(str)) {
                getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_delay, sharedPreferences.getString(str, "0")));
                return;
            } else if ("theme".equals(str) || "dark_theme".equals(str)) {
                recreate();
                return;
            } else if ("subnet".equals(str)) {
                d.f("changed ", str, this, false);
                return;
            } else if ("tethering".equals(str)) {
                d.f("changed ", str, this, false);
                return;
            } else if ("lan".equals(str)) {
                d.f("changed ", str, this, false);
                return;
            } else if ("ip6".equals(str)) {
                d.f("changed ", str, this, false);
                return;
            } else {
                String str2 = "-";
                if ("wifi_homes".equals(str)) {
                    MultiSelectListPreference multiSelectListPreference = (MultiSelectListPreference) getPreferenceScreen().findPreference(str);
                    Set<String> stringSet = sharedPreferences.getStringSet(str, new HashSet());
                    if (stringSet.size() > 0) {
                        multiSelectListPreference.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", stringSet)));
                    } else {
                        multiSelectListPreference.setTitle(getString(R.string.setting_wifi_home, "-"));
                    }
                    d.f("changed ", str, this, false);
                    return;
                } else if ("use_metered".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("unmetered_2g".equals(str) || "unmetered_3g".equals(str) || "unmetered_4g".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("national_roaming".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("eu_roaming".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("disable_on_call".equals(str)) {
                    if (!sharedPreferences.getBoolean(str, false)) {
                        d.f("changed ", str, this, false);
                        return;
                    } else if (checkPermissions(str)) {
                        d.f("changed ", str, this, false);
                        return;
                    } else {
                        return;
                    }
                } else if ("lockdown_wifi".equals(str) || "lockdown_other".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("manage_system".equals(str)) {
                    boolean z2 = sharedPreferences.getBoolean(str, false);
                    if (!z2) {
                        d.d(sharedPreferences, "show_user", true);
                    }
                    sharedPreferences.edit().putBoolean("show_system", z2).apply();
                    ServiceSinkhole.reload("changed " + str, this, false);
                    return;
                } else if ("log_app".equals(str)) {
                    C0496d.b(this).d(new Intent("eu.faircode.netguard.ACTION_RULES_CHANGED"));
                    ServiceSinkhole.reload("changed " + str, this, false);
                    return;
                } else if ("notify_access".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("filter".equals(str)) {
                    if (sharedPreferences.getBoolean(str, false)) {
                        View inflate = LayoutInflater.from(this).inflate(R.layout.filter, (ViewGroup) null, false);
                        C0091m c0091m = new C0091m(this);
                        c0091m.m(inflate);
                        c0091m.d(false);
                        c0091m.j(17039379, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i2) {
                            }
                        });
                        c0091m.h(new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                ActivitySettings.this.dialogFilter = null;
                            }
                        });
                        DialogInterfaceC0092n a2 = c0091m.a();
                        this.dialogFilter = a2;
                        a2.show();
                    }
                    ((TwoStatePreference) getPreferenceScreen().findPreference(str)).setChecked(sharedPreferences.getBoolean(str, false));
                    ServiceSinkhole.reload("changed " + str, this, false);
                    return;
                } else if ("use_hosts".equals(str)) {
                    d.f("changed ", str, this, false);
                    return;
                } else if ("vpn4".equals(str)) {
                    String string = sharedPreferences.getString(str, null);
                    try {
                        checkAddress(string, false);
                        sharedPreferences.edit().putString(str, string.trim()).apply();
                    } catch (Throwable th) {
                        sharedPreferences.edit().remove(str).apply();
                        ((EditTextPreference) getPreferenceScreen().findPreference(str)).setText(null);
                        if (!TextUtils.isEmpty(string)) {
                            Toast.makeText(this, th.toString(), 1).show();
                        }
                    }
                    getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_vpn4, sharedPreferences.getString(str, "10.1.10.1")));
                    ServiceSinkhole.reload("changed " + str, this, false);
                    return;
                } else if ("vpn6".equals(str)) {
                    String string2 = sharedPreferences.getString(str, null);
                    try {
                        checkAddress(string2, false);
                        sharedPreferences.edit().putString(str, string2.trim()).apply();
                    } catch (Throwable th2) {
                        sharedPreferences.edit().remove(str).apply();
                        ((EditTextPreference) getPreferenceScreen().findPreference(str)).setText(null);
                        if (!TextUtils.isEmpty(string2)) {
                            Toast.makeText(this, th2.toString(), 1).show();
                        }
                    }
                    getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_vpn6, sharedPreferences.getString(str, "fd00:1:fd00:1:fd00:1:fd00:1")));
                    ServiceSinkhole.reload("changed " + str, this, false);
                    return;
                } else {
                    if (!"dns".equals(str) && !"dns2".equals(str)) {
                        if ("validate".equals(str)) {
                            String string3 = sharedPreferences.getString(str, "www.google.com");
                            try {
                                checkDomain(string3);
                                sharedPreferences.edit().putString(str, string3.trim()).apply();
                            } catch (Throwable th3) {
                                sharedPreferences.edit().remove(str).apply();
                                ((EditTextPreference) getPreferenceScreen().findPreference(str)).setText(null);
                                if (!TextUtils.isEmpty(string3)) {
                                    Toast.makeText(this, th3.toString(), 1).show();
                                }
                            }
                            getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_validate, sharedPreferences.getString(str, "www.google.com")));
                            ServiceSinkhole.reload("changed " + str, this, false);
                            return;
                        } else if ("ttl".equals(str)) {
                            getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_ttl, sharedPreferences.getString(str, "259200")));
                            return;
                        } else if ("rcode".equals(str)) {
                            getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_rcode, sharedPreferences.getString(str, "3")));
                            ServiceSinkhole.reload("changed " + str, this, false);
                            return;
                        } else if ("socks5_enabled".equals(str)) {
                            d.f("changed ", str, this, false);
                            return;
                        } else if ("socks5_addr".equals(str)) {
                            String string4 = sharedPreferences.getString(str, null);
                            try {
                                if (!TextUtils.isEmpty(string4) && !Util.isNumericAddress(string4)) {
                                    throw new IllegalArgumentException("Bad address");
                                }
                            } catch (Throwable th4) {
                                sharedPreferences.edit().remove(str).apply();
                                ((EditTextPreference) getPreferenceScreen().findPreference(str)).setText(null);
                                if (!TextUtils.isEmpty(string4)) {
                                    Toast.makeText(this, th4.toString(), 1).show();
                                }
                            }
                            getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_socks5_addr, sharedPreferences.getString(str, "-")));
                            ServiceSinkhole.reload("changed " + str, this, false);
                            return;
                        } else if ("socks5_port".equals(str)) {
                            getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_socks5_port, sharedPreferences.getString(str, "-")));
                            ServiceSinkhole.reload("changed " + str, this, false);
                            return;
                        } else if ("socks5_username".equals(str)) {
                            getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_socks5_username, sharedPreferences.getString(str, "-")));
                            ServiceSinkhole.reload("changed " + str, this, false);
                            return;
                        } else if ("socks5_password".equals(str)) {
                            Preference findPreference = getPreferenceScreen().findPreference(str);
                            Object[] objArr = new Object[1];
                            if (!TextUtils.isEmpty(sharedPreferences.getString(str, ""))) {
                                str2 = "*****";
                            }
                            objArr[0] = str2;
                            findPreference.setTitle(getString(R.string.setting_socks5_password, objArr));
                            ServiceSinkhole.reload("changed " + str, this, false);
                            return;
                        } else {
                            if (!"pcap_record_size".equals(str) && !"pcap_file_size".equals(str)) {
                                if ("watchdog".equals(str)) {
                                    getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_watchdog, sharedPreferences.getString(str, "0")));
                                    ServiceSinkhole.reload("changed " + str, this, false);
                                    return;
                                } else if ("show_stats".equals(str)) {
                                    ServiceSinkhole.reloadStats("changed " + str, this);
                                    return;
                                } else if ("stats_frequency".equals(str)) {
                                    getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_stats_frequency, sharedPreferences.getString(str, "1000")));
                                    return;
                                } else if ("stats_samples".equals(str)) {
                                    getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_stats_samples, sharedPreferences.getString(str, "90")));
                                    return;
                                } else if ("hosts_url".equals(str)) {
                                    getPreferenceScreen().findPreference(str).setSummary(sharedPreferences.getString(str, "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"));
                                    return;
                                } else if ("loglevel".equals(str)) {
                                    d.f("changed ", str, this, false);
                                    return;
                                } else {
                                    return;
                                }
                            }
                            if ("pcap_record_size".equals(str)) {
                                getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_pcap_record_size, sharedPreferences.getString(str, "64")));
                            } else {
                                getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_pcap_file_size, sharedPreferences.getString(str, "2")));
                            }
                            ServiceSinkhole.setPcap(false, this);
                            File file = new File(getDir("data", 0), "netguard.pcap");
                            if (file.exists() && !file.delete()) {
                                Log.w("NetGuard.Settings", "Delete PCAP failed");
                            }
                            if (sharedPreferences.getBoolean("pcap", false)) {
                                ServiceSinkhole.setPcap(true, this);
                                return;
                            }
                            return;
                        }
                    }
                    String string5 = sharedPreferences.getString(str, null);
                    try {
                        checkAddress(string5, true);
                        sharedPreferences.edit().putString(str, string5.trim()).apply();
                    } catch (Throwable th5) {
                        sharedPreferences.edit().remove(str).apply();
                        ((EditTextPreference) getPreferenceScreen().findPreference(str)).setText(null);
                        if (!TextUtils.isEmpty(string5)) {
                            Toast.makeText(this, th5.toString(), 1).show();
                        }
                    }
                    getPreferenceScreen().findPreference(str).setTitle(getString(R.string.setting_dns, sharedPreferences.getString(str, "-")));
                    ServiceSinkhole.reload("changed " + str, this, false);
                    return;
                }
            }
        }
        d.f("changed ", str, this, false);
    }
}