I keep encountering this error. Here is my build.gradle file:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.4.1'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.4' apply false
id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
id 'com.android.library' version '8.1.4' apply false
//ksp
id 'com.google.devtools.ksp' version '1.9.10-1.0.13' apply false;
//Hilt
id 'com.google.dagger.hilt.android' version '2.48' apply false;
}
Here is the file with the function to connect to VPN:
class HomeFragment : Fragment() {
private var mService: IOpenVPNAPIService? = null
private var vpnStart = false
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentHomeBinding.inflate(inflater, container, false)
val view = binding.root
bindService()
binding.button.setOnClickListener {
if (buttonViewModel.isRunning) {
stopPulse()
stopVpn()
binding.button.setText("Connect")
} else {
startPulse()
startVpn()
binding.button.setText("Disconnect")
}
buttonViewModel.isRunning = !buttonViewModel.isRunning
}
// Restore button state when Fragment is re-displayed
if (buttonViewModel.isRunning) {
startPulse()
startVpn()
binding.button.setText("Disconnect")
}
else {
stopPulse()
stopVpn()
binding.button.setText("Connect")
}
private fun startVpn() {
if (mService != null) {
try {
requireActivity().assets.open("vietnamudp.ovpn").use { inputStream ->
Log.d("testvpn", "startVpn: ")
val isr = InputStreamReader(inputStream)
val br = BufferedReader(isr)
var config = ""
var line: String?
while (true) {
line = br.readLine()
if (line == null) break
config += line + "\n"
}
val profile = mService!!.addNewVPNProfile("jp", true, config)
mService!!.startProfile(profile.mUUID)
mService!!.startVPN(config)
vpnStart = true
binding.button.text = "Disconnect"
}
} catch (e: Exception) {
e.printStackTrace()
}
} else {
Toast.makeText(activity, "VPN service is not available", Toast.LENGTH_SHORT).show()
}
}
private fun stopVpn() {
if (mService != null) {
try {
mService!!.disconnect()
vpnStart = false
binding.button.text = "Connect"
} catch (e: Exception) {
e.printStackTrace()
}
} else {
// Handle when mService is null
}
}
private fun bindService() {
val icsopenvpnService = Intent(IOpenVPNAPIService::class.java.name)
icsopenvpnService.setPackage("com.example.app_vpn")
requireActivity().bindService(icsopenvpnService, mConnection, AppCompatActivity.BIND_AUTO_CREATE)
}
private val mConnection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder) {
mService = IOpenVPNAPIService.Stub.asInterface(service)
// Perform other operations related to service connection here
}
override fun onServiceDisconnected(className: ComponentName) {
mService = null // Set mService to null when service is disconnected
}
}
override fun onDestroy() {
super.onDestroy()
requireActivity().unbindService(mConnection)
}
}
And here is the log:
java.lang.SecurityException: Unauthorized OpenVPN API Caller
at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at de.blinkt.openvpn.api.IOpenVPNAPIService$Stub$Proxy.addNewVPNProfile(IOpenVPNAPIService.java:542)
at com.example.app_vpn.ui.auth.signup.SignUpActivity.startVpn(SignUpActivity.kt:165)
at com.example.app_vpn.ui.auth.signup.SignUpActivity.onCreate$lambda$4(SignUpActivity.kt:102)
at com.example.app_vpn.ui.auth.signup.SignUpActivity.$r8$lambda$FeCTd4qtpzwL1uSFqhOlils_ZGc(Unknown Source:0)
at com.example.app_vpn.ui.auth.signup.SignUpActivity$$ExternalSyntheticLambda3.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7750)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1218)
at android.view.View.performClickInternal(View.java:7727)
at android.view.View.access$3700(View.java:861)
at android.view.View$PerformClick.run(View.java:29141)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8250)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
The line causing the error in the HomeFragment file is:
val profile = mService!!.addNewVPNProfile("jp", true, config)
I have another project that also uses the same config file, but it works fine. Only this project consistently has this error. I am using the latest version of ics-openvpn
.
I keep encountering this error. Here is my
build.gradle
file:Here is the file with the function to connect to VPN:
And here is the log:
The line causing the error in the
HomeFragment
file is:I have another project that also uses the same config file, but it works fine. Only this project consistently has this error. I am using the latest version of ics-openvpn .