그늘 v4.6.9版本的 MD5 值为:45bd3dac9e441bb87fea09c92b437adc

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


package w;

import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import ph.u0;
import w.n;
import x.e;
public final class f {
    public final Object f14701a = new Object();
    public final ExecutorService f14702b = Executors.newFixedThreadPool(8);
    public final ConcurrentHashMap f14703c = new ConcurrentHashMap();
    public final ServerSocket f14704d;
    public final int f14705e;
    public final Thread f14706f;
    public final c f14707g;
    public final n f14708h;

    public final class a implements Runnable {
        public final Socket f14709a;

        public a(Socket socket) {
            this.f14709a = socket;
        }

        @Override
        public final void run() {
            String message;
            StringBuilder sb2;
            Socket socket = this.f14709a;
            f fVar = f.this;
            n nVar = fVar.f14708h;
            try {
                try {
                    d a10 = d.a(socket.getInputStream());
                    String a02 = u0.a0(a10.f14696a);
                    nVar.getClass();
                    if ("ping".equals(a02)) {
                        n.b(socket);
                    } else {
                        fVar.a(a02).c(a10, socket);
                    }
                    f.e(socket);
                    sb2 = new StringBuilder("Opened connections: ");
                } catch (Throwable th2) {
                    f.e(socket);
                    u0.v0("Opened connections: " + fVar.b());
                    throw th2;
                }
            } catch (SocketException unused) {
                f.e(socket);
                sb2 = new StringBuilder("Opened connections: ");
            } catch (IOException e10) {
                e = e10;
                message = new p("Error processing request", e).getMessage();
                if (!TextUtils.isEmpty(message)) {
                    Log.e("HttpProxyCacheServer error", message);
                }
                f.e(socket);
                sb2 = new StringBuilder("Opened connections: ");
            } catch (p e11) {
                e = e11;
                message = new p("Error processing request", e).getMessage();
                if (!TextUtils.isEmpty(message)) {
                }
                f.e(socket);
                sb2 = new StringBuilder("Opened connections: ");
            }
            sb2.append(fVar.b());
            u0.v0(sb2.toString());
        }
    }

    public final class b implements Runnable {
        public final CountDownLatch f14711a;

        public b(CountDownLatch countDownLatch) {
            this.f14711a = countDownLatch;
        }

        @Override
        public final void run() {
            this.f14711a.countDown();
            f fVar = f.this;
            fVar.getClass();
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    fVar.f14702b.submit(new a(fVar.f14704d.accept()));
                } catch (IOException e10) {
                    String message = new p("Error during waiting connection", e10).getMessage();
                    if (!TextUtils.isEmpty(message)) {
                        Log.e("HttpProxyCacheServer error", message);
                        return;
                    }
                    return;
                }
            }
        }
    }

    public f(c cVar) {
        this.f14707g = cVar;
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.f14704d = serverSocket;
            int localPort = serverSocket.getLocalPort();
            this.f14705e = localPort;
            List<Proxy> list = l.f14725d;
            ProxySelector.setDefault(new l(ProxySelector.getDefault(), localPort));
            CountDownLatch countDownLatch = new CountDownLatch(1);
            Thread thread = new Thread(new b(countDownLatch));
            this.f14706f = thread;
            thread.start();
            countDownLatch.await();
            this.f14708h = new n(localPort);
            u0.v0("Proxy cache server started. Is it alive? " + d());
        } catch (IOException | InterruptedException e10) {
            this.f14702b.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e10);
        }
    }

    public static void e(Socket socket) {
        try {
            if (!socket.isInputShutdown()) {
                socket.shutdownInput();
            }
        } catch (SocketException | IOException unused) {
        }
        try {
            if (!socket.isOutputShutdown()) {
                socket.shutdownOutput();
            }
        } catch (IOException e10) {
            String message = e10.getMessage();
            if (message != null && !TextUtils.isEmpty(message)) {
                Log.w("Failed to close socket on proxy side: {}. It seems client have already closed connection.", message);
            }
        }
        try {
            if (!socket.isClosed()) {
                socket.close();
            }
        } catch (IOException unused2) {
        }
    }

    public final g a(String str) throws p {
        g gVar;
        synchronized (this.f14701a) {
            gVar = (g) this.f14703c.get(str);
            if (gVar == null) {
                gVar = new g(str, this.f14707g);
                this.f14703c.put(str, gVar);
            }
        }
        return gVar;
    }

    public final int b() {
        int i;
        synchronized (this.f14701a) {
            i = 0;
            for (g gVar : this.f14703c.values()) {
                i += gVar.f14713a.get();
            }
        }
        return i;
    }

    public final String c(String str) {
        if (str != null) {
            c cVar = this.f14707g;
            if (new File(cVar.f14689a, cVar.f14690b.e(str)).exists()) {
                File file = new File(cVar.f14689a, cVar.f14690b.e(str));
                try {
                    x.e eVar = (x.e) cVar.f14691c;
                    eVar.getClass();
                    eVar.f15242a.submit(new e.a(file));
                } catch (IOException e10) {
                    u0.u0("Error touching file " + file, e10);
                }
                return Uri.fromFile(file).toString();
            } else if (d()) {
                Locale locale = Locale.US;
                Object[] objArr = new Object[3];
                objArr[0] = "127.0.0.1";
                objArr[1] = Integer.valueOf(this.f14705e);
                try {
                    objArr[2] = URLEncoder.encode(str, "utf-8");
                    return String.format(locale, "http://%s:%d/%s", objArr);
                } catch (UnsupportedEncodingException e11) {
                    throw new RuntimeException("Error encoding url", e11);
                }
            } else {
                return str;
            }
        }
        throw new NullPointerException("Url can't be null!");
    }

    public final boolean d() {
        n nVar = this.f14708h;
        nVar.getClass();
        int i = 70;
        int i10 = 0;
        while (i10 < 3) {
            try {
            } catch (InterruptedException e10) {
                e = e10;
                u0.u0("Error pinging server due to unexpected error", e);
            } catch (ExecutionException e11) {
                e = e11;
                u0.u0("Error pinging server due to unexpected error", e);
            } catch (TimeoutException unused) {
                u0.w0("Error pinging server (attempt: " + i10 + ", timeout: " + i + "). ");
            }
            if (((Boolean) nVar.f14729a.submit(new n.a()).get(i, TimeUnit.MILLISECONDS)).booleanValue()) {
                return true;
            }
            i10++;
            i *= 2;
        }
        Locale locale = Locale.US;
        Object[] objArr = new Object[3];
        objArr[0] = Integer.valueOf(i10);
        objArr[1] = Integer.valueOf(i / 2);
        try {
            objArr[2] = ProxySelector.getDefault().select(new URI(nVar.a()));
            String format = String.format(locale, "Error pinging server (attempts: %d, max timeout: %d). If you see this message, please, report at https://github.com/danikula/AndroidVideoCache/issues/134. Default proxies are: %s", objArr);
            u0.u0(format, new p(format));
            return false;
        } catch (URISyntaxException e12) {
            throw new IllegalStateException(e12);
        }
    }

    public final void f(w.b bVar) {
        bVar.getClass();
        synchronized (this.f14701a) {
            for (g gVar : this.f14703c.values()) {
                gVar.f14716d.remove(bVar);
            }
        }
    }
}