Android qt 6.7 (#1024)
* Up Gradle to 8.10 * Update Android dependencies * Up Qt to 6.7.2 * Up qtkeychain to 0.14.3 * Move function of changing the color of the navigation bar to the android side * Fix splashscreen and recent apps thumbnail backgrounds * Android authentication refactoring * Fix GitHub action * Fix the extra circle around the connect button on Android * Fix keyboard popup * Increase the amount of requestNetwork attempts on Android 11
This commit is contained in:
parent
cd70b7e619
commit
175477d31f
33 changed files with 256 additions and 192 deletions
|
|
@ -158,6 +158,10 @@ class AmneziaActivity : QtActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Log.d(TAG, "Create Amnezia activity: $intent")
|
||||
window.apply {
|
||||
addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
statusBarColor = getColor(R.color.black)
|
||||
}
|
||||
mainScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||
val proto = mainScope.async(Dispatchers.IO) {
|
||||
VpnStateStore.getVpnState().vpnProto
|
||||
|
|
@ -610,6 +614,14 @@ class AmneziaActivity : QtActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun setNavigationBarColor(color: Int) {
|
||||
Log.v(TAG, "Change navigation bar color: ${"#%08X".format(color)}")
|
||||
mainScope.launch {
|
||||
window.navigationBarColor = color
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun minimizeApp() {
|
||||
Log.v(TAG, "Minimize application")
|
||||
|
|
@ -684,6 +696,17 @@ class AmneziaActivity : QtActivity() {
|
|||
.show()
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun requestAuthentication() {
|
||||
Log.v(TAG, "Request authentication")
|
||||
mainScope.launch {
|
||||
qtInitialized.await()
|
||||
Intent(this@AmneziaActivity, AuthActivity::class.java).also {
|
||||
startActivity(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utils methods
|
||||
*/
|
||||
|
|
|
|||
97
client/android/src/org/amnezia/vpn/AuthActivity.kt
Normal file
97
client/android/src/org/amnezia/vpn/AuthActivity.kt
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package org.amnezia.vpn
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG
|
||||
import androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.biometric.BiometricPrompt.AuthenticationResult
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import org.amnezia.vpn.qt.QtAndroidController
|
||||
import org.amnezia.vpn.util.Log
|
||||
|
||||
private const val TAG = "AuthActivity"
|
||||
|
||||
private const val AUTHENTICATORS = BIOMETRIC_STRONG or DEVICE_CREDENTIAL
|
||||
|
||||
class AuthActivity : FragmentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val biometricManager = BiometricManager.from(applicationContext)
|
||||
when (biometricManager.canAuthenticate(AUTHENTICATORS)) {
|
||||
BiometricManager.BIOMETRIC_SUCCESS -> {
|
||||
showBiometricPrompt(biometricManager)
|
||||
return
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_STATUS_UNKNOWN -> {
|
||||
Log.w(TAG, "Unknown biometric status")
|
||||
showBiometricPrompt(biometricManager)
|
||||
return
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED -> {
|
||||
Log.e(TAG, "The specified options are incompatible with the current Android " +
|
||||
"version ${Build.VERSION.SDK_INT}")
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE -> {
|
||||
Log.w(TAG, "The hardware is unavailable")
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
|
||||
Log.w(TAG, "No biometric or device credential is enrolled")
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> {
|
||||
Log.w(TAG, "There is no suitable hardware")
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED -> {
|
||||
Log.w(TAG, "A security vulnerability has been discovered with one or " +
|
||||
"more hardware sensors")
|
||||
}
|
||||
}
|
||||
QtAndroidController.onAuthResult(true)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun showBiometricPrompt(biometricManager: BiometricManager) {
|
||||
val executor = ContextCompat.getMainExecutor(applicationContext)
|
||||
val biometricPrompt = BiometricPrompt(this, executor,
|
||||
object : BiometricPrompt.AuthenticationCallback() {
|
||||
override fun onAuthenticationSucceeded(result: AuthenticationResult) {
|
||||
super.onAuthenticationSucceeded(result)
|
||||
Log.d(TAG, "Authentication succeeded")
|
||||
QtAndroidController.onAuthResult(true)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onAuthenticationFailed() {
|
||||
super.onAuthenticationFailed()
|
||||
Log.w(TAG, "Authentication failed")
|
||||
}
|
||||
|
||||
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
||||
super.onAuthenticationError(errorCode, errString)
|
||||
Log.e(TAG, "Authentication error $errorCode: $errString")
|
||||
QtAndroidController.onAuthResult(false)
|
||||
finish()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||
.setAllowedAuthenticators(AUTHENTICATORS)
|
||||
.setTitle("AmneziaVPN")
|
||||
.setSubtitle(biometricManager.getStrings(AUTHENTICATORS)?.promptMessage)
|
||||
.build()
|
||||
|
||||
biometricPrompt.authenticate(promptInfo)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package org.amnezia.vpn;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Intent;
|
||||
import org.qtproject.qt.android.bindings.QtActivity;
|
||||
|
||||
|
||||
import static android.content.Context.KEYGUARD_SERVICE;
|
||||
|
||||
public class AuthHelper extends QtActivity {
|
||||
|
||||
static final String TAG = "AuthHelper";
|
||||
|
||||
public static Intent getAuthIntent(Context context) {
|
||||
KeyguardManager mKeyguardManager = (KeyguardManager)context.getSystemService(KEYGUARD_SERVICE);
|
||||
if (mKeyguardManager.isDeviceSecure()) {
|
||||
return mKeyguardManager.createConfirmDeviceCredentialIntent(null, null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,10 +33,10 @@ class ImportConfigActivity : ComponentActivity() {
|
|||
intent?.let(::readConfig)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
Log.d(TAG, "onNewIntent: $intent")
|
||||
intent?.let(::readConfig)
|
||||
intent.let(::readConfig)
|
||||
}
|
||||
|
||||
private fun readConfig(intent: Intent) {
|
||||
|
|
|
|||
|
|
@ -25,5 +25,7 @@ object QtAndroidController {
|
|||
|
||||
external fun onConfigImported(data: String)
|
||||
|
||||
external fun onAuthResult(result: Boolean)
|
||||
|
||||
external fun decodeQrCode(data: String): Boolean
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue