|
@@ -124,6 +124,8 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
|
|
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
|
|
|
|
+ Log.d("AutoConnectService", "onStartCommand")
|
|
|
+
|
|
|
startForegroundNotification()
|
|
|
startListenerIKEV2()
|
|
|
|
|
@@ -134,7 +136,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
val channelId = "FastestVPN_Foreground_Wifi"
|
|
|
val channel =
|
|
|
- NotificationChannel(channelId, "FastestVPN", NotificationManager.IMPORTANCE_LOW)
|
|
|
+ NotificationChannel(channelId, "FastestVPN", NotificationManager.IMPORTANCE_HIGH)
|
|
|
val notificationManager = getSystemService(
|
|
|
NotificationManager::class.java
|
|
|
)
|
|
@@ -147,7 +149,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
.setContentText("Auto-connect feature will automatically detect network changes as set in the app settings.")
|
|
|
.setColor(applicationContext.resources.getColor(R.color.blue_text))
|
|
|
.setSmallIcon(R.drawable.ic_logo_notify)
|
|
|
- startForeground(1, notification.build())
|
|
|
+ startForeground(10, notification.build())
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -266,6 +268,17 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
else if (!isTrustedWifiConnected && isConnect == App.DISCONNECTED) {
|
|
|
Log.d("AutoConnectService", "Connect VPN")
|
|
|
startVpn()
|
|
|
+
|
|
|
+
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+// Log.d("wg test s fore", "startForegroundService")
|
|
|
+//
|
|
|
+// applicationContext.startForegroundService(Intent(applicationContext, WireGuardService::class.java))
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// Log.d("wg test s serv", "startService")
|
|
|
+// applicationContext.startService(Intent(applicationContext, WireGuardService::class.java))
|
|
|
+// }
|
|
|
}
|
|
|
else if (isTrustedWifiConnected && isConnect == App.CONNECTING) {
|
|
|
Log.d("AutoConnectService", "Connecting VPN")
|
|
@@ -302,7 +315,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
countDownTimer()
|
|
|
try {
|
|
|
basePreferenceHelper = BasePreferenceHelper(applicationContext)
|
|
|
- Log.d("auto_conn startVpn", App.connection_status.toString())
|
|
|
+ Log.d("auto_conn startVpn", "startVpn() " + App.connection_status.toString())
|
|
|
if (CheckInternetConnection.getInternetConnection(applicationContext).isConnectedToInternet) {
|
|
|
if (basePreferenceHelper.getProtocol().title.toLowerCase()
|
|
|
.contentEquals(AppEnum.WG_PROTOCOL.key.toLowerCase())
|
|
@@ -314,10 +327,14 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
else if (basePreferenceHelper.getProtocol().title.contentEquals(AppEnum.IKEV2_PROTOCOL.key))
|
|
|
{
|
|
|
|
|
|
+ Log.d("auto_conn startVpn", "IKEv2 Connection Outside")
|
|
|
+
|
|
|
basePreferenceHelper.getConnectedServer().let { server ->
|
|
|
|
|
|
+
|
|
|
+ Log.d("auto_conn startVpn", "IKEv2 Connection Inside")
|
|
|
+
|
|
|
/*Connect IKEV2*/
|
|
|
- Log.d("auto_conn onstart", "IKEv2 Connection")
|
|
|
|
|
|
// startListenerIKEV2()
|
|
|
// App.createIKEV2Listener()
|
|
@@ -357,7 +374,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
fun startTcpUDP() {
|
|
|
Log.d("auto_conn startVpn", "startTcpUDP()")
|
|
|
|
|
|
- countDownTimer?.start()
|
|
|
+// countDownTimer?.start()
|
|
|
|
|
|
/*Connect UDP,TCP*/
|
|
|
App.connection_status = App.CONNECTION_STATE_CONNECTING
|
|
@@ -498,10 +515,13 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
.contentEquals(AppEnum.WG_PROTOCOL.key.toLowerCase())
|
|
|
)
|
|
|
{
|
|
|
+ Log.d("auto_conn stopVpn", "vpnWireGuardPermission stop")
|
|
|
vpnWireGuardPermission(false)
|
|
|
}
|
|
|
else if (basePreferenceHelper.getProtocol().title.contentEquals(AppEnum.IKEV2_PROTOCOL.key))
|
|
|
{
|
|
|
+ Log.d("auto_conn stopVpn", "IKEv2 stop")
|
|
|
+
|
|
|
/*Disconnect IKEV2*/
|
|
|
val intent = Intent(applicationContext, VpnProfileControlActivity::class.java)
|
|
|
intent.action = VpnProfileControlActivity.DISCONNECT
|
|
@@ -520,6 +540,8 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
|
|
|
// applicationContext.unbindService(mConnection)
|
|
|
|
|
|
+ Log.d("auto_conn stopVpn", "OpenVPN stop")
|
|
|
+
|
|
|
Log.d("auto_conn msr mcon", App.mService.toString() + " " + mConnection.toString())
|
|
|
|
|
|
/*Disconnect TCP,UDP*/
|
|
@@ -554,19 +576,19 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
- widgetIntent.action = SimpleAppWidget.ACTION_STOP_SERVICE
|
|
|
- applicationContext.sendBroadcast(widgetIntent)
|
|
|
-
|
|
|
- Handler().postDelayed({
|
|
|
- try {
|
|
|
- LocalBroadcastManager.getInstance(applicationContext)
|
|
|
- .unregisterReceiver(ikevConnectionStatesReceiverAutoConnect)
|
|
|
-
|
|
|
- } catch (e: Exception) {
|
|
|
- e.printStackTrace()
|
|
|
- }
|
|
|
- }, 500)
|
|
|
+// val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
+// widgetIntent.action = SimpleAppWidget.ACTION_STOP_SERVICE
|
|
|
+// applicationContext.sendBroadcast(widgetIntent)
|
|
|
+//
|
|
|
+// Handler().postDelayed({
|
|
|
+// try {
|
|
|
+// LocalBroadcastManager.getInstance(applicationContext)
|
|
|
+// .unregisterReceiver(ikevConnectionStatesReceiverAutoConnect)
|
|
|
+//
|
|
|
+// } catch (e: Exception) {
|
|
|
+// e.printStackTrace()
|
|
|
+// }
|
|
|
+// }, 500)
|
|
|
|
|
|
} catch (e: Exception) {
|
|
|
e.printStackTrace()
|
|
@@ -784,7 +806,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
|
|
|
// basePreferenceHelper.setConnectState(App.CONNECTED)
|
|
|
val connectState1 = basePreferenceHelper.getConnectState()
|
|
|
- Log.d("auto_conn ip w", "ACTION_VPN_CONNECTED widget $connectState $connectState1")
|
|
|
+// Log.d("auto_conn ip w", "ACTION_VPN_CONNECTED widget $connectState $connectState1")
|
|
|
// if (connectState1 == 2) {
|
|
|
// val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
// widgetIntent.action = SimpleAppWidget.ACTION_CONNECT_VPN
|
|
@@ -792,7 +814,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
// }
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_DISABLED -> {
|
|
|
- Log.d("auto_conn ip w", "ACTION_VPN_DISABLED widget $connectState")
|
|
|
+// Log.d("auto_conn ip w", "ACTION_VPN_DISABLED widget $connectState")
|
|
|
|
|
|
if (connectState == App.CONNECTING)
|
|
|
{
|
|
@@ -822,11 +844,11 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
}
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_NOT_CONNECTED -> {
|
|
|
- Log.d("auto_conn ip w", "ACTION_VPN_NOT_CONNECTED widget $connectState")
|
|
|
+// Log.d("auto_conn ip w", "ACTION_VPN_NOT_CONNECTED widget $connectState")
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_CONNECTING -> {
|
|
|
val connectState1 = basePreferenceHelper.getConnectState()
|
|
|
- Log.d("auto_conn ip w", "ACTION_VPN_CONNECTING widget $connectState1")
|
|
|
+// Log.d("auto_conn ip w", "ACTION_VPN_CONNECTING widget $connectState1")
|
|
|
App.connection_status = App.CONNECTION_STATE_CONNECTING
|
|
|
MainActivity.vpnConnectionCallBacks?.onVpnConnecting()
|
|
|
|
|
@@ -837,7 +859,7 @@ class AutoConnectService : Service(), VpnStatus.StateListener {
|
|
|
applicationContext?.sendBroadcast(widgetIntent)
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_SERVER_NOT_RESPONDING -> {
|
|
|
- Log.d("auto_conn ip w", "ACTION_VPN_SERVER_NOT_RESPONDING widget")
|
|
|
+// Log.d("auto_conn ip w", "ACTION_VPN_SERVER_NOT_RESPONDING widget")
|
|
|
App.connection_status = App.CONNECTION_STATE_SERVER_NOT_RESPONDING
|
|
|
if (basePreferenceHelper.getProtocol().index == 0)
|
|
|
{
|