百度手机卫士 v8.8.0版本的 MD5 值为:a85894a6923c8a39f0c3a3a686ad7443
以下内容为反编译后的 LocalVpnService.java 源代码,内容仅作参考
package com.quickbird.mini.vpn.vpn;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.net.VpnService;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import com.quickbird.mini.utils.Constants;
import com.quickbird.sdk.QuickBird;
import com.quickbird.sdk.utils.QBLogger;
import java.io.IOException;
@TargetApi(14)
public class LocalVpnService extends VpnService {
public static final String ACTION_START_SAFE_VPN = "START_SAFE_VPN";
public static final String ACTION_STOP_SAFE_VPN = "STOP_SAFE_VPN";
public static final String PAUSE_VPN_ACTION = "PAUSE_VPN_ACTION";
public static final String START_VPN_ACTION = "VPN_START_ACTION";
public static final String STOP_VPN_ACTION = "VPN_STOP_ACTION";
private static final String TAG = "QbSdk";
private static final String TUN_DEVICE_ADDRESS = "192.168.19.19";
private static final String VPN_ROUTE_ADDRESS = "0.0.0.0";
private static final int WATCHDOG_THREAD_JOIN_TIMEOUT = 60000;
private VpnConnectTask mVpnConnectTask;
private VpnDisconnectTask mVpnDisconnectTask;
private ParcelFileDescriptor mVpnFD;
private VpnServiceManager mVpnMgr;
private boolean mVpnPaused = false;
private VpnWatchdogThread mWatchdogThread;
public static long CURRENT_TRAFFIC_COUNT = 0;
private static LocalVpnService sIntance = null;
@Override
public void onRevoke() {
super.onRevoke();
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Vpn deactivated by system.");
}
this.mVpnMgr.onVpnDisconnect();
onStopVpn();
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
String str = null;
if (intent != null) {
str = intent.getAction();
}
if (TextUtils.isEmpty(str)) {
return super.onStartCommand(intent, i, i2);
}
if (str.equals(START_VPN_ACTION)) {
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Local vpn service : start vpn action.");
}
onStartVpn();
} else if (str.equals(STOP_VPN_ACTION)) {
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Local vpn service : stop vpn action.");
}
onStopVpn();
} else if (str.equals(PAUSE_VPN_ACTION)) {
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Local vpn service : pause vpn action.");
}
onPauseVpn();
} else if (ACTION_START_SAFE_VPN.equals(str)) {
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Local vpn service : start safe vpn");
}
onStartVpn();
} else if (ACTION_STOP_SAFE_VPN.equals(str)) {
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Local vpn service : stop safe vpn");
}
onStopVpn();
}
return super.onStartCommand(intent, i, i2);
}
@Override
public void onCreate() {
super.onCreate();
sIntance = this;
this.mVpnMgr = VpnServiceManager.getInstance(getApplication());
}
@Override
public void onDestroy() {
onStopVpn();
}
public static LocalVpnService getInstance() {
return sIntance;
}
private synchronized void asyncConnect() {
if (this.mVpnConnectTask == null) {
this.mVpnConnectTask = new VpnConnectTask();
this.mVpnConnectTask.start();
}
}
private synchronized void asyncDisconnect() {
if (this.mVpnDisconnectTask == null) {
this.mVpnDisconnectTask = new VpnDisconnectTask();
this.mVpnDisconnectTask.start();
}
}
public static boolean protectSocket(int i) {
if (getInstance() == null) {
return false;
}
return getInstance().protect(i);
}
private void onStopVpn() {
boolean z = !this.mVpnMgr.isQbVpnOpened();
boolean z2 = this.mVpnMgr.isSafeVpnOpened() ? false : true;
if (z) {
this.mVpnPaused = false;
}
if (z && z2) {
asyncDisconnect();
}
}
private void onStartVpn() {
if (this.mVpnMgr.isQbVpnOpened()) {
this.mVpnPaused = false;
}
if (sIntance.mWatchdogThread == null || !sIntance.mWatchdogThread.isUP()) {
asyncConnect();
}
}
public void onPauseVpn() {
this.mVpnPaused = true;
if (sIntance.mWatchdogThread == null || !sIntance.mWatchdogThread.isUP()) {
asyncConnect();
}
}
public static boolean isVpnConnected(Context context) {
if (sIntance == null || sIntance.mWatchdogThread == null) {
return false;
}
return sIntance.mWatchdogThread.isUP();
}
public static boolean isVpnPaused() {
if (sIntance == null) {
return false;
}
return sIntance.mVpnPaused;
}
public void waitForWatchdogStart() {
if (this.mWatchdogThread != null) {
this.mWatchdogThread.terminate();
this.mWatchdogThread = null;
}
this.mWatchdogThread = new VpnWatchdogThread(this, this.mVpnFD);
this.mWatchdogThread.start();
}
public class VpnConnectTask extends Thread {
private long startTime;
private VpnConnectTask() {
this.startTime = System.currentTimeMillis();
}
@Override
public void run() {
try {
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Start vpn connect task.");
}
VpnService.Builder builder = new VpnService.Builder(LocalVpnService.this);
builder.addAddress(LocalVpnService.TUN_DEVICE_ADDRESS, 32);
builder.addRoute(LocalVpnService.VPN_ROUTE_ADDRESS, 0);
builder.setSession(LocalVpnService.this.mVpnMgr.getVpnServiceName());
AudioManager audioManager = (AudioManager) LocalVpnService.this.getSystemService("audio");
int streamVolume = audioManager.getStreamVolume(5);
int vibrateSetting = audioManager.getVibrateSetting(1);
try {
audioManager.setStreamVolume(5, 0, 0);
audioManager.setVibrateSetting(1, 0);
LocalVpnService.this.mVpnFD = builder.establish();
LocalVpnService.this.waitForWatchdogStart();
LocalVpnService.this.sendBroadcast(new Intent("com.dianxinos.optimizer.action.VPN_START"));
audioManager.setStreamVolume(5, streamVolume, 0);
audioManager.setVibrateSetting(1, vibrateSetting);
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Vpn connect used time : " + (System.currentTimeMillis() - this.startTime));
}
} catch (Throwable th) {
audioManager.setStreamVolume(5, streamVolume, 0);
audioManager.setVibrateSetting(1, vibrateSetting);
throw th;
}
} catch (Exception e) {
if (QuickBird.SDK_DEBUG) {
QBLogger.e("QbSdk", "Vpn connect error!!!");
}
}
synchronized (LocalVpnService.this) {
LocalVpnService.this.mVpnConnectTask = null;
}
}
}
public class VpnDisconnectTask extends Thread {
private long startTime;
private VpnDisconnectTask() {
this.startTime = System.currentTimeMillis();
}
@Override
public void run() {
Intent intent;
LocalVpnService localVpnService;
try {
try {
if (LocalVpnService.this.mWatchdogThread != null && LocalVpnService.this.mWatchdogThread.isAlive()) {
LocalVpnService.this.mWatchdogThread.terminate();
LocalVpnService.this.mWatchdogThread.join(Constants.MINUTE_MS);
LocalVpnService.this.mWatchdogThread = null;
}
closeFd();
intent = new Intent("com.dianxinos.optimizer.action.VPN_STOP");
localVpnService = LocalVpnService.this;
} catch (Exception e) {
e.printStackTrace();
closeFd();
intent = new Intent("com.dianxinos.optimizer.action.VPN_STOP");
localVpnService = LocalVpnService.this;
}
localVpnService.sendBroadcast(intent);
synchronized (LocalVpnService.this) {
if (LocalVpnService.sIntance != null) {
LocalVpnService.sIntance.stopSelf();
}
LocalVpnService.this.mVpnDisconnectTask = null;
}
if (QuickBird.SDK_DEBUG) {
QBLogger.d("QbSdk", "Vpn disconnect used time : " + (System.currentTimeMillis() - this.startTime));
}
} catch (Throwable th) {
closeFd();
LocalVpnService.this.sendBroadcast(new Intent("com.dianxinos.optimizer.action.VPN_STOP"));
throw th;
}
}
private void closeFd() {
LocalVpnService localVpnService;
if (LocalVpnService.this.mVpnFD != null) {
try {
try {
LocalVpnService.this.mVpnFD.close();
localVpnService = LocalVpnService.this;
} catch (IOException e) {
e.printStackTrace();
localVpnService = LocalVpnService.this;
}
localVpnService.mVpnFD = null;
} catch (Throwable th) {
LocalVpnService.this.mVpnFD = null;
throw th;
}
}
}
}
}