|
@@ -28,6 +28,7 @@ import com.vpn.fastestvpnservice.constants.AppEnum
|
|
|
import com.vpn.fastestvpnservice.constants.splitList
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
import com.vpn.fastestvpnservice.openVpnUtils.EncryptData
|
|
|
+import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.homeViewModel1
|
|
|
import com.vpn.fastestvpnservice.widgets.SimpleAppWidget
|
|
|
import com.wireguard.android.backend.GoBackend
|
|
|
import com.wireguard.android.backend.Tunnel
|
|
@@ -146,6 +147,8 @@ class WireGuardService : Service(), VpnStatus.StateListener {
|
|
|
val intent = Intent(applicationContext, VpnProfileControlActivity::class.java)
|
|
|
App.connection_status = App.CONNECTION_STATE_CONNECTING
|
|
|
MainActivity.vpnConnectionCallBacks?.onVpnConnecting()
|
|
|
+
|
|
|
+ basePreferenceHelper.setConnectState(App.CONNECTING)
|
|
|
val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
widgetIntent.action = SimpleAppWidget.ACTION_CONNECTING_VPN
|
|
|
applicationContext?.sendBroadcast(widgetIntent)
|
|
@@ -303,7 +306,8 @@ class WireGuardService : Service(), VpnStatus.StateListener {
|
|
|
try {
|
|
|
basePreferenceHelper = BasePreferenceHelper(applicationContext)
|
|
|
|
|
|
- Log.d("wg test s stopVpn", App.connection_status.toString())
|
|
|
+ val connectState = basePreferenceHelper.getConnectState()
|
|
|
+ Log.d("wg test s stopVpn", "connectState = $connectState")
|
|
|
|
|
|
/*Disconnect Wireguard*/
|
|
|
if (basePreferenceHelper.getProtocol().title.toLowerCase()
|
|
@@ -320,6 +324,9 @@ class WireGuardService : Service(), VpnStatus.StateListener {
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
applicationContext.startActivity(intent)
|
|
|
|
|
|
+ basePreferenceHelper.setConnectState(App.DISCONNECTED)
|
|
|
+
|
|
|
+
|
|
|
// App.connection_status = App.CONNECTION_STATE_DISCONNECTED
|
|
|
// MainActivity.vpnConnectionCallBacks?.onVpnDisconnected()
|
|
|
}
|
|
@@ -639,32 +646,46 @@ class WireGuardService : Service(), VpnStatus.StateListener {
|
|
|
override fun onReceive(context: Context?, intent: Intent?) {
|
|
|
if (intent != null && intent.action != null) {
|
|
|
basePreferenceHelper = BasePreferenceHelper(applicationContext)
|
|
|
+ val connectState = basePreferenceHelper.getConnectState()
|
|
|
val action = intent.action
|
|
|
when (action) {
|
|
|
CharonVpnService.ACTION_VPN_CONNECTED -> {
|
|
|
- Log.d("vpnConnectionCall ip w", "ACTION_VPN_CONNECTED widget " + App.connection_status)
|
|
|
App.connection_status = App.CONNECTION_STATE_CONNECTED
|
|
|
MainActivity.vpnConnectionCallBacks?.onVpnConnected()
|
|
|
- val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
- widgetIntent.action = SimpleAppWidget.ACTION_CONNECT_VPN
|
|
|
- applicationContext?.sendBroadcast(widgetIntent)
|
|
|
+
|
|
|
+// basePreferenceHelper.setConnectState(App.CONNECTED)
|
|
|
+ val connectState1 = basePreferenceHelper.getConnectState()
|
|
|
+ Log.d("vpnConnectionCall ip w", "ACTION_VPN_CONNECTED widget $connectState $connectState1")
|
|
|
+// if (connectState1 == 2) {
|
|
|
+// val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
+// widgetIntent.action = SimpleAppWidget.ACTION_CONNECT_VPN
|
|
|
+// applicationContext?.sendBroadcast(widgetIntent)
|
|
|
+// }
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_DISABLED -> {
|
|
|
- Log.d("vpnConnectionCall ip w", "ACTION_VPN_DISABLED widget " + App.connection_status)
|
|
|
+ Log.d("vpnConnectionCall ip w", "ACTION_VPN_DISABLED widget $connectState")
|
|
|
|
|
|
- if (App.connection_status == App.CONNECTION_STATE_CONNECTING)
|
|
|
+ if (connectState == App.CONNECTING)
|
|
|
{
|
|
|
+ Log.d("vpnConnectionCall ip w", "ACTION_VPN_DISABLED ==> $connectState")
|
|
|
App.connection_status = App.CONNECTION_STATE_CONNECTING
|
|
|
MainActivity.vpnConnectionCallBacks?.onVpnConnecting()
|
|
|
|
|
|
+ basePreferenceHelper.setConnectState(App.CONNECTING)
|
|
|
+
|
|
|
val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
widgetIntent.action = SimpleAppWidget.ACTION_CONNECTING_VPN
|
|
|
applicationContext?.sendBroadcast(widgetIntent)
|
|
|
}
|
|
|
else {
|
|
|
+ Log.d("vpnConnectionCall ip w",
|
|
|
+ "ACTION_VPN_DISABLED ==> else $connectState"
|
|
|
+ )
|
|
|
App.connection_status = App.CONNECTION_STATE_DISCONNECTED
|
|
|
MainActivity.vpnConnectionCallBacks?.onVpnDisconnected()
|
|
|
|
|
|
+ basePreferenceHelper.setConnectState(App.DISCONNECTED)
|
|
|
+
|
|
|
val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
widgetIntent.action = SimpleAppWidget.ACTION_DISCONNECT_VPN
|
|
|
applicationContext?.sendBroadcast(widgetIntent)
|
|
@@ -672,15 +693,15 @@ class WireGuardService : Service(), VpnStatus.StateListener {
|
|
|
}
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_NOT_CONNECTED -> {
|
|
|
- Log.d("vpnConnectionCall ip w", "ACTION_VPN_NOT_CONNECTED widget " + App.connection_status)
|
|
|
-// App.connection_status = App.CONNECTION_STATE_DISCONNECTED
|
|
|
-// MainActivity.vpnConnectionCallBacks?.onVpnDisconnected()
|
|
|
+ Log.d("vpnConnectionCall ip w", "ACTION_VPN_NOT_CONNECTED widget $connectState")
|
|
|
}
|
|
|
CharonVpnService.ACTION_VPN_CONNECTING -> {
|
|
|
Log.d("vpnConnectionCall ip w", "ACTION_VPN_CONNECTING widget")
|
|
|
App.connection_status = App.CONNECTION_STATE_CONNECTING
|
|
|
MainActivity.vpnConnectionCallBacks?.onVpnConnecting()
|
|
|
|
|
|
+ basePreferenceHelper.setConnectState(App.CONNECTING)
|
|
|
+
|
|
|
val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
widgetIntent.action = SimpleAppWidget.ACTION_CONNECTING_VPN
|
|
|
applicationContext?.sendBroadcast(widgetIntent)
|
|
@@ -692,6 +713,11 @@ class WireGuardService : Service(), VpnStatus.StateListener {
|
|
|
{
|
|
|
Log.d("vpnConnectionCall ip w", "ACTION_VPN_SERVER_NOT_RESPONDING tcp/udp")
|
|
|
startTcpUDP()
|
|
|
+ } else {
|
|
|
+ basePreferenceHelper.setConnectState(App.DISCONNECTED)
|
|
|
+ val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|
|
|
+ widgetIntent.action = SimpleAppWidget.ACTION_DISCONNECT_VPN
|
|
|
+ applicationContext?.sendBroadcast(widgetIntent)
|
|
|
}
|
|
|
MainActivity.vpnConnectionCallBacks?.onServerNotResponding()
|
|
|
val widgetIntent = Intent(applicationContext, SimpleAppWidget::class.java)
|