Skip to content

Commit c1d996c

Browse files
committed
show error on vpn permission denial.
1 parent 988b881 commit c1d996c

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

base/src/main/java/com/windscribe/vpn/alert/ForegroundAlert.kt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fun showRetryDialog(message: String, retryCallBack: () -> Unit, cancelCallBack:
1919
dialog.dismiss()
2020
if (which == AlertDialog.BUTTON_POSITIVE) {
2121
retryCallBack()
22-
}else if(which == AlertDialog.BUTTON_NEGATIVE){
22+
} else if (which == AlertDialog.BUTTON_NEGATIVE) {
2323
cancelCallBack()
2424
}
2525
}
@@ -110,12 +110,39 @@ fun showAlertDialog(
110110
positionButtonLabel,
111111
DialogInterface.OnClickListener(function = listener)
112112
)
113-
setNegativeButton(negativeButtonLabel, DialogInterface.OnClickListener(function = listener))
113+
setNegativeButton(
114+
negativeButtonLabel,
115+
DialogInterface.OnClickListener(function = listener)
116+
)
114117
show()
115118
}
116119
}
117120
}
118121

122+
fun showErrorDialog(activity: Activity, message: String, callBack: () -> Unit) {
123+
val builder = createDialogBuilder(activity, message)
124+
activity.let {
125+
it.runOnUiThread {
126+
builder.setOnDismissListener {
127+
callBack()
128+
}
129+
builder.setOnCancelListener {
130+
callBack()
131+
}
132+
val listener = { dialog: DialogInterface, _: Int ->
133+
dialog.dismiss()
134+
}
135+
with(builder) {
136+
setNeutralButton(
137+
appContext.getString(R.string.ok),
138+
DialogInterface.OnClickListener(function = listener)
139+
)
140+
show()
141+
}
142+
}
143+
}
144+
}
145+
119146
fun safeDialog(block: (activity: Activity) -> Unit) {
120147
appContext.activeActivity?.let {
121148
it.runOnUiThread {

base/src/main/java/com/windscribe/vpn/backend/utils/VPNPermissionActivity.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import android.os.Bundle
1515
import com.windscribe.vpn.R.layout
1616
import com.windscribe.vpn.Windscribe
1717
import com.windscribe.vpn.Windscribe.Companion.appContext
18+
import com.windscribe.vpn.alert.showAlertDialog
19+
import com.windscribe.vpn.alert.showErrorDialog
1820
import com.windscribe.vpn.autoconnection.ProtocolInformation
1921
import com.windscribe.vpn.backend.VpnBackendHolder
2022
import com.windscribe.vpn.repository.LocationRepository
@@ -121,9 +123,19 @@ class VPNPermissionActivity : Activity() {
121123
}
122124
} else if (resultCode == RESULT_CANCELED) {
123125
logger.debug("User denied VPN permission.")
124-
scope.launch {
125-
vpnController.disconnectAsync()
126-
finish()
126+
showErrorDialog(this,
127+
"Windscribe requires VPN permission to configure VPN. " +
128+
"Sometimes you may see this error if another VPN app is configured as 'Always on VPN'. " +
129+
"Please turn off 'Always on' in all profiles.") {
130+
scope.launch {
131+
try {
132+
vpnController.disconnectAsync()
133+
} catch (e: Exception) {
134+
logger.error("Failed to disconnect VPN: ${e.message}")
135+
} finally {
136+
finish()
137+
}
138+
}
127139
}
128140
}
129141
}

0 commit comments

Comments
 (0)