MD5 校验值:d47de9d0b292a5cbd7377502c33607ba
V2RayServiceManager.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.v2ray.ang.service; import a0.j; import a9.y; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.util.Log; import androidx.core.graphics.drawable.IconCompat; import c5.a; import c5.c; import c5.d; import com.bumptech.glide.e; import com.bumptech.glide.f; import com.network.StreamForwarder; import com.tencent.mmkv.MMKV; import com.v2ray.ang.dto.ServerConfig; import com.v2ray.ang.dto.V2rayConfig; import com.v2ray.ang.dto.V2rayConfigModel; import com.v2ray.ang.service.V2RayServiceManager; import go.Seq; import go.libv2ray.gojni.R; import h4.b; import i.c0; import java.io.File; import java.io.IOException; import java.lang.ref.SoftReference; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import kotlin.Metadata; import l3.g; import libv2ray.Libv2ray; import libv2ray.V2RayPoint; import p.n; import r5.i; import r8.r; import z.l; @Metadata(d1 = {"\u0000x\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\b\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0006\bÇ\u0002\u0018\u00002\u00020\u0001:\u0002\u001dDB\t\b\u0002¢\u0006\u0004\bB\u0010CJ\u0010\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0002J\b\u0010\u0006\u001a\u00020\u0002H\u0003J\n\u0010\b\u001a\u0004\u0018\u00010\u0007H\u0002J\u0018\u0010\f\u001a\u00020\u00042\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u000b\u001a\u00020\u0002H\u0007J\u000e\u0010\u000f\u001a\u00020\u00042\u0006\u0010\u000e\u001a\u00020\rJ\u0006\u0010\u0010\u001a\u00020\u0004J\u0006\u0010\u0011\u001a\u00020\u0004R\u0014\u0010\u0013\u001a\u00020\u00128\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0013\u0010\u0014R\u0014\u0010\u0015\u001a\u00020\u00128\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0015\u0010\u0014R\u0014\u0010\u0016\u001a\u00020\u00128\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0016\u0010\u0014R\u0014\u0010\u0017\u001a\u00020\u00128\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0017\u0010\u0014R\u0017\u0010\u0019\u001a\u00020\u00188\u0006¢\u0006\f\n\u0004\b\u0019\u0010\u001a\u001a\u0004\b\u001b\u0010\u001cR\u0018\u0010\u001e\u001a\u0004\u0018\u00010\u001d8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u001e\u0010\u001fR#\u0010&\u001a\n !*\u0004\u0018\u00010 0 8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b\"\u0010#\u001a\u0004\b$\u0010%R:\u0010*\u001a\n\u0012\u0004\u0012\u00020(\u0018\u00010'2\u000e\u0010)\u001a\n\u0012\u0004\u0012\u00020(\u0018\u00010'8\u0006@FX\u0086\u000e¢\u0006\u0012\n\u0004\b*\u0010+\u001a\u0004\b,\u0010-\"\u0004\b.\u0010/R$\u00101\u001a\u0004\u0018\u0001008\u0006@\u0006X\u0086\u000e¢\u0006\u0012\n\u0004\b1\u00102\u001a\u0004\b3\u00104\"\u0004\b5\u00106R\u0016\u00108\u001a\u0002078\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b8\u00109R\u0018\u0010;\u001a\u0004\u0018\u00010:8\u0002@\u0002X\u0083\u000e¢\u0006\u0006\n\u0004\b;\u0010<R\u0018\u0010=\u001a\u0004\u0018\u00010\u00078\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b=\u0010>R\u0018\u0010@\u001a\u0004\u0018\u00010?8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b@\u0010A¨\u0006E"}, d2 = {"Lcom/v2ray/ang/service/V2RayServiceManager;", "", "", "name", "Lr5/l;", "showNotification", "createNotificationChannel", "Landroid/app/NotificationManager;", "getNotificationManager", "Landroid/content/Context;", "context", "config", "startV2Ray", "Lcom/v2ray/ang/dto/V2rayConfigModel;", "v2rayConfigModel", "startV2rayPoint", "stopV2rayPoint", "cancelNotification", "", "NOTIFICATION_ID", "I", "NOTIFICATION_PENDING_INTENT_CONTENT", "NOTIFICATION_PENDING_INTENT_STOP_V2RAY", "NOTIFICATION_ICON_THRESHOLD", "Llibv2ray/V2RayPoint;", "v2rayPoint", "Llibv2ray/V2RayPoint;", "getV2rayPoint", "()Llibv2ray/V2RayPoint;", "Lc5/c;", "mMsgReceive", "Lc5/c;", "Lcom/tencent/mmkv/MMKV;", "kotlin.jvm.PlatformType", "settingsStorage$delegate", "Lr5/c;", "getSettingsStorage", "()Lcom/tencent/mmkv/MMKV;", "settingsStorage", "Ljava/lang/ref/SoftReference;", "Lc5/a;", "value", "serviceControl", "Ljava/lang/ref/SoftReference;", "getServiceControl", "()Ljava/lang/ref/SoftReference;", "setServiceControl", "(Ljava/lang/ref/SoftReference;)V", "Lcom/v2ray/ang/dto/ServerConfig;", "currentConfig", "Lcom/v2ray/ang/dto/ServerConfig;", "getCurrentConfig", "()Lcom/v2ray/ang/dto/ServerConfig;", "setCurrentConfig", "(Lcom/v2ray/ang/dto/ServerConfig;)V", "", "lastQueryTime", "J", "Lp/n;", "mBuilder", "Lp/n;", "mNotificationManager", "Landroid/app/NotificationManager;", "Lh4/b;", "localServer", "Lh4/b;", "<init>", "()V", "a9/y", "v2rayLib_release"}, k = 1, mv = {1, 7, 1}) public final class V2RayServiceManager { public static final V2RayServiceManager INSTANCE = new V2RayServiceManager(); private static final int NOTIFICATION_ICON_THRESHOLD = 3000; private static final int NOTIFICATION_ID = 1557; private static final int NOTIFICATION_PENDING_INTENT_CONTENT = 0; private static final int NOTIFICATION_PENDING_INTENT_STOP_V2RAY = 1; private static ServerConfig currentConfig; private static long lastQueryTime; private static b localServer; private static n mBuilder; private static c mMsgReceive; private static NotificationManager mNotificationManager; private static SoftReference<a> serviceControl; private static final r5.c settingsStorage; private static final V2RayPoint v2rayPoint; static { boolean z9; y yVar = new y(); if (Build.VERSION.SDK_INT >= 25) { z9 = true; } else { z9 = false; } V2RayPoint newV2RayPoint = Libv2ray.newV2RayPoint(yVar, z9); e.l("newV2RayPoint(V2RayCallb…uild.VERSION_CODES.N_MR1)", newV2RayPoint); v2rayPoint = newV2RayPoint; settingsStorage = new i(d.f1417o); } private V2RayServiceManager() { } private final String createNotificationChannel() { l.i(); NotificationChannel c4 = j.c(); c4.setLightColor(-12303292); c4.setImportance(0); c4.setLockscreenVisibility(0); NotificationManager notificationManager = getNotificationManager(); if (notificationManager == null) { return "RAY_NG_M_CH_ID"; } notificationManager.createNotificationChannel(c4); return "RAY_NG_M_CH_ID"; } private final NotificationManager getNotificationManager() { a aVar; if (mNotificationManager == null) { SoftReference<a> softReference = serviceControl; if (softReference == null || (aVar = softReference.get()) == null) { return null; } Object systemService = ((V2RayVpnService) aVar).getSystemService("notification"); e.k("null cannot be cast to non-null type android.app.NotificationManager", systemService); mNotificationManager = (NotificationManager) systemService; } return mNotificationManager; } private final MMKV getSettingsStorage() { return (MMKV) settingsStorage.getValue(); } private final void showNotification(String str) { a aVar; int i10; String str2; int i11; SoftReference<a> softReference = serviceControl; if (softReference != null && (aVar = softReference.get()) != null) { V2RayVpnService v2RayVpnService = (V2RayVpnService) aVar; Intent intent = new Intent(); intent.setClassName(v2RayVpnService, "com.dtunnel.presenter.MainActivity"); intent.addFlags(268468224); Intent intent2 = new Intent(v2RayVpnService, (Class<?>) V2RayVpnService.class); intent2.setAction("STOP_VPN_SERVICE"); int i12 = Build.VERSION.SDK_INT; int i13 = 134217728; if (i12 >= 23) { i10 = 201326592; } else { i10 = 134217728; } PendingIntent service = PendingIntent.getService(v2RayVpnService, 1, intent2, i10); if (i12 >= 23) { i13 = 201326592; } PendingIntent activity = PendingIntent.getActivity(v2RayVpnService, 0, intent, i13); if (i12 >= 26) { str2 = createNotificationChannel(); } else { str2 = ""; } n nVar = new n(v2RayVpnService, str2); if (v2rayPoint.getIsRunning()) { i11 = R.drawable.ic_rocket_on; } else { i11 = R.drawable.ic_rocket_off; } nVar.f6899q.icon = i11; nVar.f6887e = n.c(str); nVar.f6890h = 2; nVar.d(2, true); nVar.f6891i = true; nVar.d(8, true); nVar.f6889g = activity; nVar.f6884b.add(new p.l(IconCompat.b(R.drawable.ic_rocket_off), v2RayVpnService.getString(R.string.notification_action_stop_v2ray), service, new Bundle(), null, null, true, 0, true, false, false)); nVar.f6892j = true; mBuilder = nVar; v2RayVpnService.startForeground(NOTIFICATION_ID, nVar.a()); } } public static final void m4startV2rayPoint$lambda1(V2rayConfigModel v2rayConfigModel, String str, int i10, h4.a aVar) { e.m("$v2rayConfigModel", v2rayConfigModel); f4.c b10 = c0.b(v2rayConfigModel.getTunnelType(), str, i10, new e4.a(v2rayConfigModel.getProxy(), v2rayConfigModel.getPort(), v2rayConfigModel.getPayload()), v2rayConfigModel.getSni(), v2rayConfigModel.getTlsVersion()); b10.f2664c = new g(); Socket socket = aVar.f3254a; Socket b11 = b10.b(); new StreamForwarder(socket, b11).start(ParcelFileDescriptor.fromSocket(socket).detachFd(), ParcelFileDescriptor.fromSocket(b11).detachFd()); } public static final boolean m5startV2rayPoint$lambda1$lambda0(Socket socket) { a aVar; SoftReference<a> softReference = serviceControl; if (softReference != null && (aVar = softReference.get()) != null) { return ((V2RayVpnService) aVar).protect(ParcelFileDescriptor.fromSocket(socket).getFd()); } return true; } public final void cancelNotification() { a aVar; SoftReference<a> softReference = serviceControl; if (softReference == null || (aVar = softReference.get()) == null) { return; } ((V2RayVpnService) aVar).stopForeground(true); mBuilder = null; } public final ServerConfig getCurrentConfig() { return currentConfig; } public final SoftReference<a> getServiceControl() { return serviceControl; } public final V2RayPoint getV2rayPoint() { return v2rayPoint; } public final void setCurrentConfig(ServerConfig serverConfig) { currentConfig = serverConfig; } public final void setServiceControl(SoftReference<a> softReference) { Context context; String absolutePath; String str; a aVar; a aVar2; serviceControl = softReference; V2RayVpnService v2RayVpnService = null; if (softReference != null && (aVar2 = softReference.get()) != null) { context = ((V2RayVpnService) aVar2).getApplicationContext(); } else { context = null; } Seq.setContext(context); i iVar = d5.a.f2258a; if (softReference != null && (aVar = softReference.get()) != null) { v2RayVpnService = (V2RayVpnService) aVar; } if (v2RayVpnService == null) { absolutePath = ""; } else { File externalFilesDir = v2RayVpnService.getExternalFilesDir("assets"); if (externalFilesDir == null) { absolutePath = v2RayVpnService.getDir("assets", 0).getAbsolutePath(); str = "context.getDir(AppConfig…R_ASSETS, 0).absolutePath"; } else { absolutePath = externalFilesDir.getAbsolutePath(); str = "extDir.absolutePath"; } e.l(str, absolutePath); } Libv2ray.initV2Env(absolutePath); } public final void startV2Ray(Context context, String str) { e.m("context", context); e.m("config", str); a.a.d(5, context); Intent intent = new Intent(context.getApplicationContext(), (Class<?>) V2RayVpnService.class); intent.putExtra("config", V2rayConfigModel.INSTANCE.fromExternalJson(str).toJson()); if (Build.VERSION.SDK_INT > 25) { context.startForegroundService(intent); } else { context.startService(intent); } } public final void startV2rayPoint(final V2rayConfigModel v2rayConfigModel) { a aVar; d5.b bVar; boolean z9; e.m("v2rayConfigModel", v2rayConfigModel); SoftReference<a> softReference = serviceControl; if (softReference != null && (aVar = softReference.get()) != null) { V2RayVpnService v2RayVpnService = (V2RayVpnService) aVar; ServerConfig s9 = com.bumptech.glide.c.s(v2rayConfigModel.decodeConfig()); if (s9 == null) { return; } final String hostAddress = InetAddress.getByName(v2rayConfigModel.getProxy()).getHostAddress(); final int port = v2rayConfigModel.getPort(); if (localServer == null && !e.h(v2rayConfigModel.getMode(), o2.e.V2RAY)) { b bVar2 = new b(5502); localServer = bVar2; ServerSocket serverSocket = new ServerSocket(); bVar2.f3256n = serverSocket; serverSocket.bind(new InetSocketAddress("127.0.0.1", bVar2.f3255m)); b bVar3 = localServer; if (bVar3 != null) { bVar3.f3257o = new h4.c() { @Override public final void a(h4.a aVar2) { V2RayServiceManager.m4startV2rayPoint$lambda1(V2rayConfigModel.this, hostAddress, port, aVar2); } }; } if (bVar3 != null) { bVar3.start(); } } if (!v2rayPoint.getIsRunning()) { i iVar = d5.c.f2261a; String uuid = v2rayConfigModel.getUuid(); String password = v2rayConfigModel.getPassword(); String mode = v2rayConfigModel.getMode(); try { V2rayConfig.OutboundBean proxyOutbound = s9.getProxyOutbound(); if (proxyOutbound == null) { bVar = new d5.b(); } else { bVar = d5.c.c(v2RayVpnService, proxyOutbound, uuid, password, mode); Log.d("com.v2ray.ang", bVar.f2260b); } } catch (Exception e10) { e10.printStackTrace(); bVar = new d5.b(); } if (!bVar.f2259a) { return; } try { mMsgReceive = new c(v2rayConfigModel); v2RayVpnService.registerReceiver(mMsgReceive, new IntentFilter("com.logger.DT_ACTION_SERVICE")); } catch (Exception e11) { Log.d("com.v2ray.ang", e11.toString()); } V2RayPoint v2RayPoint = v2rayPoint; v2RayPoint.setConfigureFileContent(bVar.f2260b); v2RayPoint.setDomainName(s9.getV2rayPointDomainAndPort()); currentConfig = s9; try { MMKV settingsStorage2 = getSettingsStorage(); if (settingsStorage2 != null) { z9 = settingsStorage2.b("pref_prefer_ipv6"); } else { z9 = false; } v2RayPoint.runLoop(z9); } catch (Exception e12) { Log.d("com.v2ray.ang", e12.toString()); } if (v2rayPoint.getIsRunning()) { a.a.d(6, v2RayVpnService); showNotification(v2rayConfigModel.getName()); } else { a.a.d(7, v2RayVpnService); cancelNotification(); } } } } public final void stopV2rayPoint() { a aVar; b bVar = localServer; if (bVar != null) { try { ServerSocket serverSocket = bVar.f3256n; if (serverSocket != null && !serverSocket.isClosed()) { bVar.f3256n.close(); } } catch (IOException e10) { e10.printStackTrace(); } } localServer = null; SoftReference<a> softReference = serviceControl; if (softReference != null && (aVar = softReference.get()) != null) { V2RayVpnService v2RayVpnService = (V2RayVpnService) aVar; if (v2rayPoint.getIsRunning()) { f.z(r.f7862a, new c5.e(null)); } cancelNotification(); try { v2RayVpnService.unregisterReceiver(mMsgReceive); a.a.d(13, v2RayVpnService); } catch (Exception e11) { Log.d("com.v2ray.ang", e11.toString()); } } } }