Files
amnezia-client/client/android/src/org/amnezia/vpn/qt/VPNPermissionHelper.kt
T

42 lines
1.3 KiB
Kotlin
Raw Normal View History

2021-09-30 15:56:48 +03:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.amnezia.vpn.qt
import android.content.Context
import android.content.Intent
2021-10-09 20:17:19 +03:00
import android.util.Log
2021-09-30 15:56:48 +03:00
class VPNPermissionHelper : android.net.VpnService() {
2021-10-09 20:17:19 +03:00
private val tag = "VPNPermissionHelper"
2021-09-30 15:56:48 +03:00
/**
* This small service does nothing else then checking if the vpn permission
* is present and prompting if not.
*/
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
2021-10-13 18:33:43 +03:00
Log.i(tag, "onStartCommand")
2021-09-30 15:56:48 +03:00
val intent = prepare(this.applicationContext)
if (intent != null) {
startActivityForResult(intent)
}
return START_NOT_STICKY
}
companion object {
@JvmStatic
fun startService(c: Context) {
val appC = c.applicationContext
appC.startService(Intent(appC, VPNPermissionHelper::class.java))
}
}
/**
* Fetches the Global QTAndroidActivity and calls startActivityForResult with the given intent
* Is used to request the VPN-Permission, if not given.
* Actually Implemented in src/platforms/android/AndroidController.cpp
*/
external fun startActivityForResult(i: Intent)
}