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

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


package eu.faircode.netguard;

import B.b;
import android.app.IntentService;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.core.app.r;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.util.Date;
public class ServiceExternal extends IntentService {
    public ServiceExternal() {
        super("NetGuard.External");
    }

    private static Notification getForegroundNotification(Context context) {
        r rVar = new r(context, "foreground");
        rVar.n(R.drawable.ic_hourglass_empty_white_24dp);
        rVar.l(-2);
        rVar.d();
        rVar.o(1);
        rVar.i(context.getString(R.string.app_name));
        return rVar.a();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        InputStream inputStream;
        URLConnection uRLConnection;
        HttpURLConnection httpURLConnection;
        FileOutputStream fileOutputStream;
        HttpURLConnection httpURLConnection2;
        try {
            startForeground(9, getForegroundNotification(this));
            Log.i("NetGuard.External", "Received " + intent);
            Util.logExtras(intent);
            if ("eu.faircode.netguard.DOWNLOAD_HOSTS_FILE".equals(intent.getAction())) {
                SharedPreferences f = b.f(this);
                FileOutputStream fileOutputStream2 = null;
                String string = f.getString("hosts_url", null);
                if ("https://www.netguard.me/hosts".equals(string)) {
                    string = "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts";
                }
                File file = new File(getFilesDir(), "hosts.tmp");
                File file2 = new File(getFilesDir(), "hosts.txt");
                try {
                    uRLConnection = new URL(string).openConnection();
                    try {
                        uRLConnection.connect();
                        if (uRLConnection instanceof HttpURLConnection) {
                            if (((HttpURLConnection) uRLConnection).getResponseCode() != 200) {
                                throw new IOException(httpURLConnection2.getResponseCode() + " " + httpURLConnection2.getResponseMessage());
                            }
                        }
                        Log.i("NetGuard.External", "Content length=" + uRLConnection.getContentLength());
                        inputStream = uRLConnection.getInputStream();
                        try {
                            fileOutputStream = new FileOutputStream(file);
                        } catch (Throwable th) {
                            th = th;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        inputStream = null;
                    }
                } catch (Throwable th3) {
                    th = th3;
                    inputStream = null;
                    uRLConnection = null;
                }
                try {
                    byte[] bArr = new byte[4096];
                    long j2 = 0;
                    while (true) {
                        int read = inputStream.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        fileOutputStream.write(bArr, 0, read);
                        j2 += read;
                    }
                    Log.i("NetGuard.External", "Downloaded size=" + j2);
                    if (file2.exists()) {
                        file2.delete();
                    }
                    file.renameTo(file2);
                    f.edit().putString("hosts_last_download", DateFormat.getDateTimeInstance().format(Long.valueOf(new Date().getTime()))).apply();
                    ServiceSinkhole.reload("hosts file download", this, false);
                    try {
                        fileOutputStream.close();
                    } catch (IOException e2) {
                        Log.e("NetGuard.External", e2.toString() + "\n" + Log.getStackTraceString(e2));
                    }
                    try {
                        inputStream.close();
                    } catch (IOException e3) {
                        Log.e("NetGuard.External", e3.toString() + "\n" + Log.getStackTraceString(e3));
                    }
                } catch (Throwable th4) {
                    th = th4;
                    fileOutputStream2 = fileOutputStream;
                    Log.e("NetGuard.External", th.toString() + "\n" + Log.getStackTraceString(th));
                    if (file.exists()) {
                        file.delete();
                    }
                    if (fileOutputStream2 != null) {
                        try {
                            fileOutputStream2.close();
                        } catch (IOException e4) {
                            Log.e("NetGuard.External", e4.toString() + "\n" + Log.getStackTraceString(e4));
                        }
                    }
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e5) {
                            Log.e("NetGuard.External", e5.toString() + "\n" + Log.getStackTraceString(e5));
                        }
                    }
                    if (uRLConnection instanceof HttpURLConnection) {
                        httpURLConnection = (HttpURLConnection) uRLConnection;
                        httpURLConnection.disconnect();
                    }
                }
                if (uRLConnection instanceof HttpURLConnection) {
                    httpURLConnection = (HttpURLConnection) uRLConnection;
                    httpURLConnection.disconnect();
                }
            }
        } finally {
            stopForeground(true);
        }
    }
}