diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0c9dfb32..73182aeb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -381,7 +381,7 @@ jobs: env: ANDROID_BUILD_PLATFORM: android-34 - QT_VERSION: 6.7.3 + QT_VERSION: 6.6.3 QT_MODULES: 'qtremoteobjects qt5compat qtimageformats qtshadertools' PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }} PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }} @@ -398,7 +398,7 @@ jobs: version: ${{ env.QT_VERSION }} host: 'linux' target: 'desktop' - arch: 'linux_gcc_64' + arch: 'gcc_64' modules: ${{ env.QT_MODULES }} dir: ${{ runner.temp }} py7zrversion: '==0.22.*' diff --git a/CMakeLists.txt b/CMakeLists.txt index fec613de..bf2a9008 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ string(TIMESTAMP CURRENT_DATE "%Y-%m-%d") set(RELEASE_DATE "${CURRENT_DATE}") set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}) -set(APP_ANDROID_VERSION_CODE 2087) +set(APP_ANDROID_VERSION_CODE 1087) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(MZ_PLATFORM_NAME "linux") diff --git a/client/android/AndroidManifest.xml b/client/android/AndroidManifest.xml index b28f754b..314df0de 100644 --- a/client/android/AndroidManifest.xml +++ b/client/android/AndroidManifest.xml @@ -3,10 +3,13 @@ + + @@ -67,6 +70,9 @@ android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --" /> + = Build.VERSION_CODES.Q) { - try { - configBuilder.setHttpProxy(ProxyInfo.buildDirectProxy(host, port)) - } catch (e: Exception) { - Log.e(TAG, "Could not set proxy: ${e.message}") - return false - } - } return true } diff --git a/client/android/protocolApi/src/main/kotlin/Protocol.kt b/client/android/protocolApi/src/main/kotlin/Protocol.kt index 6e682aa4..8aa72c39 100644 --- a/client/android/protocolApi/src/main/kotlin/Protocol.kt +++ b/client/android/protocolApi/src/main/kotlin/Protocol.kt @@ -113,12 +113,7 @@ abstract class Protocol { Log.d(TAG, "addRoute: $inetNetwork") vpnBuilder.addRoute(inetNetwork) } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - Log.d(TAG, "excludeRoute: $inetNetwork") - vpnBuilder.excludeRoute(inetNetwork) - } else { - Log.e(TAG, "Trying to exclude route $inetNetwork on old Android") - } + Log.e(TAG, "Trying to exclude route $inetNetwork on old Android") } } @@ -135,13 +130,6 @@ abstract class Protocol { Log.d(TAG, "setMtu: ${config.mtu}") vpnBuilder.setMtu(config.mtu) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - config.httpProxy?.let { - Log.d(TAG, "setHttpProxy: $it") - vpnBuilder.setHttpProxy(it) - } - } - if (config.allowAllAF) { Log.d(TAG, "allowFamily") vpnBuilder.allowFamily(OsConstants.AF_INET) @@ -151,8 +139,6 @@ abstract class Protocol { Log.d(TAG, "setBlocking: ${config.blockingMode}") vpnBuilder.setBlocking(config.blockingMode) vpnBuilder.setUnderlyingNetworks(null) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - vpnBuilder.setMetered(false) } } diff --git a/client/android/protocolApi/src/main/kotlin/ProtocolConfig.kt b/client/android/protocolApi/src/main/kotlin/ProtocolConfig.kt index bebcea4c..3310c300 100644 --- a/client/android/protocolApi/src/main/kotlin/ProtocolConfig.kt +++ b/client/android/protocolApi/src/main/kotlin/ProtocolConfig.kt @@ -145,7 +145,7 @@ open class ProtocolConfig protected constructor( } // for older versions of Android, build a list of subnets without excluded routes // and add them to routes - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU && routes.any { !it.include }) { + if (routes.any { !it.include }) { val ipRangeSet = IpRangeSet() routes.forEach { if (it.include) ipRangeSet.add(IpRange(it.inetNetwork)) diff --git a/client/android/qt/build.gradle.kts b/client/android/qt/build.gradle.kts index 6b1d3fd1..139adf4f 100644 --- a/client/android/qt/build.gradle.kts +++ b/client/android/qt/build.gradle.kts @@ -21,5 +21,5 @@ android { } dependencies { - api(fileTree(mapOf("dir" to "../libs", "include" to listOf("*.jar")))) + implementation(fileTree(mapOf("dir" to "../libs", "include" to listOf("*.jar")))) } diff --git a/client/android/src/org/amnezia/vpn/AmneziaActivity.kt b/client/android/src/org/amnezia/vpn/AmneziaActivity.kt index c6db5e29..ad958204 100644 --- a/client/android/src/org/amnezia/vpn/AmneziaActivity.kt +++ b/client/android/src/org/amnezia/vpn/AmneziaActivity.kt @@ -3,9 +3,7 @@ package org.amnezia.vpn import android.Manifest import android.annotation.SuppressLint import android.app.AlertDialog -import android.app.NotificationManager import android.content.ActivityNotFoundException -import android.content.BroadcastReceiver import android.content.ComponentName import android.content.Intent import android.content.Intent.EXTRA_MIME_TYPES @@ -77,7 +75,6 @@ class AmneziaActivity : QtActivity() { private var isWaitingStatus = true private var isServiceConnected = false private var isInBoundState = false - private var notificationStateReceiver: BroadcastReceiver? = null private lateinit var vpnServiceMessenger: IpcMessenger private var pfd: ParcelFileDescriptor? = null @@ -186,7 +183,6 @@ class AmneziaActivity : QtActivity() { doBindService() } ) - registerBroadcastReceivers() intent?.let(::processIntent) runBlocking { vpnProto = proto.await() } } @@ -202,26 +198,6 @@ class AmneziaActivity : QtActivity() { } } - private fun registerBroadcastReceivers() { - notificationStateReceiver = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - registerBroadcastReceiver( - arrayOf( - NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED, - NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED - ) - ) { - Log.v( - TAG, "Notification state changed: ${it?.action}, blocked = " + - "${it?.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false)}" - ) - mainScope.launch { - qtInitialized.await() - QtAndroidController.onNotificationStateChanged() - } - } - } else null - } - override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) Log.v(TAG, "onNewIntent: $intent") @@ -267,8 +243,6 @@ class AmneziaActivity : QtActivity() { override fun onDestroy() { Log.d(TAG, "Destroy Amnezia activity") - unregisterBroadcastReceiver(notificationStateReceiver) - notificationStateReceiver = null mainScope.cancel() super.onDestroy() } @@ -747,7 +721,7 @@ class AmneziaActivity : QtActivity() { } @Suppress("unused") - fun isNotificationPermissionGranted(): Boolean = applicationContext.isNotificationPermissionGranted() + fun isNotificationPermissionGranted(): Boolean = true @Suppress("unused") fun requestNotificationPermission() { @@ -847,67 +821,6 @@ class AmneziaActivity : QtActivity() { 0, 0, 1.0f, 1.0f, 0, 0, 0,0 ) - // workaround for a bug in Qt that causes the mouse click event not to be handled - // also disable right-click, as it causes the application to crash - private var lastButtonState = 0 - private fun MotionEvent.fixCopy(): MotionEvent = MotionEvent.obtain( - downTime, - eventTime, - action, - pointerCount, - (0 until pointerCount).map { i -> - MotionEvent.PointerProperties().apply { - getPointerProperties(i, this) - } - }.toTypedArray(), - (0 until pointerCount).map { i -> - MotionEvent.PointerCoords().apply { - getPointerCoords(i, this) - } - }.toTypedArray(), - metaState, - MotionEvent.BUTTON_PRIMARY, - xPrecision, - yPrecision, - deviceId, - edgeFlags, - source, - flags - ) - - private fun handleMouseEvent(ev: MotionEvent, superDispatch: (MotionEvent?) -> Boolean): Boolean { - when (ev.action) { - MotionEvent.ACTION_DOWN -> { - lastButtonState = ev.buttonState - if (ev.buttonState == MotionEvent.BUTTON_SECONDARY) return true - } - - MotionEvent.ACTION_UP -> { - when (lastButtonState) { - MotionEvent.BUTTON_SECONDARY -> return true - MotionEvent.BUTTON_PRIMARY -> { - val modEvent = ev.fixCopy() - return superDispatch(modEvent).apply { modEvent.recycle() } - } - } - } - } - return superDispatch(ev) - } - - override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { - Log.v(TAG, "dispatchTouch: $ev") - if (ev != null && ev.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { - return handleMouseEvent(ev) { super.dispatchTouchEvent(it) } - } - return super.dispatchTouchEvent(ev) - } - - override fun dispatchTrackballEvent(ev: MotionEvent?): Boolean { - ev?.let { return handleMouseEvent(ev) { super.dispatchTrackballEvent(it) }} - return super.dispatchTrackballEvent(ev) - } - /** * Utils methods */ diff --git a/client/android/src/org/amnezia/vpn/AmneziaTileService.kt b/client/android/src/org/amnezia/vpn/AmneziaTileService.kt index 32d5710d..117755e2 100644 --- a/client/android/src/org/amnezia/vpn/AmneziaTileService.kt +++ b/client/android/src/org/amnezia/vpn/AmneziaTileService.kt @@ -1,12 +1,9 @@ package org.amnezia.vpn -import android.annotation.SuppressLint -import android.app.PendingIntent import android.content.ComponentName import android.content.Intent import android.content.ServiceConnection import android.net.VpnService -import android.os.Build import android.os.IBinder import android.os.Messenger import android.service.quicksettings.Tile @@ -148,7 +145,8 @@ class AmneziaTileService : TileService() { Intent(this, AmneziaActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }.also { - startActivityAndCollapseCompat(it) + @Suppress("DEPRECATION") + startActivityAndCollapse(it) } } } @@ -192,7 +190,8 @@ class AmneziaTileService : TileService() { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(EXTRA_PROTOCOL, vpnProto) }.also { - startActivityAndCollapseCompat(it) + @Suppress("DEPRECATION") + startActivityAndCollapse(it) } false } else { @@ -216,23 +215,6 @@ class AmneziaTileService : TileService() { private fun stopVpn() = vpnServiceMessenger.send(Action.DISCONNECT) - @SuppressLint("StartActivityAndCollapseDeprecated") - private fun startActivityAndCollapseCompat(intent: Intent) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - startActivityAndCollapse( - PendingIntent.getActivity( - applicationContext, - 0, - intent, - PendingIntent.FLAG_IMMUTABLE - ) - ) - } else { - @Suppress("DEPRECATION") - startActivityAndCollapse(intent) - } - } - private fun updateVpnState(state: ProtocolState) = scope.launch { VpnStateStore.store { it.copy(protocolState = state) } } @@ -249,17 +231,14 @@ class AmneziaTileService : TileService() { when (val protocolState = vpnState.protocolState) { CONNECTED -> { state = Tile.STATE_ACTIVE - subtitleCompat = null } DISCONNECTED, UNKNOWN -> { state = Tile.STATE_INACTIVE - subtitleCompat = null } CONNECTING, DISCONNECTING, RECONNECTING -> { state = Tile.STATE_UNAVAILABLE - subtitleCompat = getString(protocolState) } } updateTile() @@ -267,17 +246,4 @@ class AmneziaTileService : TileService() { // double update to fix weird visual glitches tile.updateTile() } - - private var Tile.subtitleCompat: CharSequence? - set(value) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - this.subtitle = value - } - } - get() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - return this.subtitle - } - return null - } } diff --git a/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt b/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt index 8d108bc3..85f06b36 100644 --- a/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt +++ b/client/android/src/org/amnezia/vpn/AmneziaVpnService.kt @@ -3,14 +3,10 @@ package org.amnezia.vpn import android.annotation.SuppressLint import android.app.ActivityManager import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE -import android.app.NotificationManager import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST -import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED import android.net.VpnService -import android.os.Build import android.os.Handler import android.os.IBinder import android.os.Looper @@ -104,7 +100,6 @@ open class AmneziaVpnService : VpnService() { private lateinit var networkState: NetworkState private lateinit var trafficStats: TrafficStats private var controlReceiver: BroadcastReceiver? = null - private var notificationStateReceiver: BroadcastReceiver? = null private var screenOnReceiver: BroadcastReceiver? = null private var screenOffReceiver: BroadcastReceiver? = null private val clientMessengers = ConcurrentHashMap() @@ -189,16 +184,6 @@ open class AmneziaVpnService : VpnService() { Messenger(actionMessageHandler) } - /** - * Notification setup - */ - private val foregroundServiceTypeCompat - get() = when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED - Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> FOREGROUND_SERVICE_TYPE_MANIFEST - else -> 0 - } - private val serviceNotification: ServiceNotification by lazy(NONE) { ServiceNotification(this) } /** @@ -232,7 +217,7 @@ open class AmneziaVpnService : VpnService() { ServiceCompat.startForeground( this, NOTIFICATION_ID, serviceNotification.buildNotification(serverName, vpnProto?.label, protocolState.value), - foregroundServiceTypeCompat + 0 ) return START_REDELIVER_INTENT } @@ -309,23 +294,6 @@ open class AmneziaVpnService : VpnService() { } } - notificationStateReceiver = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - registerBroadcastReceiver( - arrayOf( - NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED, - NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED - ) - ) { - val state = it?.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false) - Log.v(TAG, "Notification state changed: ${it?.action}, blocked = $state") - if (state == false) { - enableNotification() - } else { - disableNotification() - } - } - } else null - registerScreenStateBroadcastReceivers() } @@ -353,10 +321,8 @@ open class AmneziaVpnService : VpnService() { private fun unregisterBroadcastReceivers() { Log.d(TAG, "Unregister broadcast receivers") unregisterBroadcastReceiver(controlReceiver) - unregisterBroadcastReceiver(notificationStateReceiver) unregisterScreenStateBroadcastReceivers() controlReceiver = null - notificationStateReceiver = null } /** diff --git a/client/android/src/org/amnezia/vpn/ServiceNotification.kt b/client/android/src/org/amnezia/vpn/ServiceNotification.kt index 47e8f263..f2980df6 100644 --- a/client/android/src/org/amnezia/vpn/ServiceNotification.kt +++ b/client/android/src/org/amnezia/vpn/ServiceNotification.kt @@ -1,19 +1,15 @@ package org.amnezia.vpn -import android.Manifest.permission import android.annotation.SuppressLint import android.app.Notification -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent -import android.content.pm.PackageManager import android.os.Build import androidx.core.app.NotificationChannelCompat.Builder import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.Action import androidx.core.app.NotificationManagerCompat -import androidx.core.content.ContextCompat import org.amnezia.vpn.protocol.ProtocolState import org.amnezia.vpn.protocol.ProtocolState.CONNECTED import org.amnezia.vpn.protocol.ProtocolState.DISCONNECTED @@ -85,27 +81,17 @@ class ServiceNotification(private val context: Context) { .setSubText(getSpeedString(speed)) .build() - fun isNotificationEnabled(): Boolean { - if (!context.isNotificationPermissionGranted()) return false - if (!notificationManager.areNotificationsEnabled()) return false - return notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID)?.let { - it.importance != NotificationManager.IMPORTANCE_NONE - } ?: true - } + fun isNotificationEnabled(): Boolean = notificationManager.areNotificationsEnabled() @SuppressLint("MissingPermission") fun updateNotification(serverName: String?, protocol: String?, state: ProtocolState) { - if (context.isNotificationPermissionGranted()) { - Log.v(TAG, "Update notification: $serverName, $state") - notificationManager.notify(NOTIFICATION_ID, buildNotification(serverName, protocol, state)) - } + Log.v(TAG, "Update notification: $serverName, $state") + notificationManager.notify(NOTIFICATION_ID, buildNotification(serverName, protocol, state)) } @SuppressLint("MissingPermission") fun updateSpeed(speed: TrafficData) { - if (context.isNotificationPermissionGranted()) { - notificationManager.notify(NOTIFICATION_ID, buildNotification(speed)) - } + notificationManager.notify(NOTIFICATION_ID, buildNotification(speed)) } private fun getSpeedString(traffic: TrafficData) = @@ -166,8 +152,3 @@ class ServiceNotification(private val context: Context) { } } } - -fun Context.isNotificationPermissionGranted(): Boolean = - Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || - ContextCompat.checkSelfPermission(this, permission.POST_NOTIFICATIONS) == - PackageManager.PERMISSION_GRANTED diff --git a/client/android/src/org/amnezia/vpn/VpnRequestActivity.kt b/client/android/src/org/amnezia/vpn/VpnRequestActivity.kt index c24f5a19..56bcbdea 100644 --- a/client/android/src/org/amnezia/vpn/VpnRequestActivity.kt +++ b/client/android/src/org/amnezia/vpn/VpnRequestActivity.kt @@ -7,7 +7,6 @@ import android.content.Intent import android.content.res.Configuration.UI_MODE_NIGHT_MASK import android.content.res.Configuration.UI_MODE_NIGHT_YES import android.net.VpnService -import android.os.Build import android.os.Bundle import android.provider.Settings import android.widget.Toast @@ -31,12 +30,9 @@ class VpnRequestActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, "Start request activity") - vpnProto = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - intent.extras?.getSerializable(EXTRA_PROTOCOL, VpnProto::class.java) - } else { - @Suppress("DEPRECATION") - intent.extras?.getSerializable(EXTRA_PROTOCOL) as VpnProto - } + @Suppress("DEPRECATION") + vpnProto = intent.extras?.getSerializable(EXTRA_PROTOCOL) as VpnProto + val requestIntent = VpnService.prepare(applicationContext) if (requestIntent != null) { if (getSystemService()!!.isKeyguardLocked) { diff --git a/client/android/utils/src/main/kotlin/Log.kt b/client/android/utils/src/main/kotlin/Log.kt index da11c200..42832b0d 100644 --- a/client/android/utils/src/main/kotlin/Log.kt +++ b/client/android/utils/src/main/kotlin/Log.kt @@ -1,6 +1,8 @@ package org.amnezia.vpn.util import android.content.Context +import android.icu.text.DateFormat +import android.icu.text.SimpleDateFormat import android.os.Build import android.os.Process import java.io.File @@ -8,8 +10,8 @@ import java.io.IOException import java.io.RandomAccessFile import java.nio.channels.FileChannel import java.nio.channels.FileLock -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter +import java.util.Date +import java.util.Locale import java.util.concurrent.locks.ReentrantLock import org.amnezia.vpn.util.Log.Priority.D import org.amnezia.vpn.util.Log.Priority.E @@ -37,7 +39,9 @@ private const val LOG_MAX_FILE_SIZE = 1024 * 1024 * | | | create a report and/or terminate the process | */ object Log { - private val dateTimeFormat: DateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN) + private val dateTimeFormat = object : ThreadLocal() { + override fun initialValue(): DateFormat = SimpleDateFormat(DATE_TIME_PATTERN, Locale.US) + } private lateinit var logDir: File private val logFile: File by lazy { File(logDir, LOG_FILE_NAME) } @@ -135,7 +139,7 @@ object Log { } private fun formatLogMsg(tag: String, msg: String, priority: Priority): String { - val date = LocalDateTime.now().format(dateTimeFormat) + val date = dateTimeFormat.get()?.format(Date()) return "$date ${Process.myPid()} ${Process.myTid()} $priority [${Thread.currentThread().name}] " + "$tag: $msg\n" } diff --git a/client/android/utils/src/main/kotlin/net/NetworkState.kt b/client/android/utils/src/main/kotlin/net/NetworkState.kt index 1cab5535..51f674c0 100644 --- a/client/android/utils/src/main/kotlin/net/NetworkState.kt +++ b/client/android/utils/src/main/kotlin/net/NetworkState.kt @@ -8,11 +8,9 @@ import android.net.NetworkCapabilities import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET import android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED import android.net.NetworkRequest -import android.os.Build import android.os.Handler import androidx.core.content.getSystemService import kotlin.LazyThreadSafetyMode.NONE -import kotlinx.coroutines.delay import org.amnezia.vpn.util.Log private const val TAG = "NetworkState" @@ -47,7 +45,9 @@ class NetworkState( override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities) { Log.v(TAG, "onCapabilitiesChanged: $network, $networkCapabilities") - checkNetworkState(network, networkCapabilities) + handler.post { + checkNetworkState(network, networkCapabilities) + } } private fun checkNetworkState(network: Network, networkCapabilities: NetworkCapabilities) { @@ -76,33 +76,10 @@ class NetworkState( } } - suspend fun bindNetworkListener() { + fun bindNetworkListener() { if (isListenerBound) return Log.d(TAG, "Bind network listener") - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - connectivityManager.registerBestMatchingNetworkCallback(networkRequest, networkCallback, handler) - } else { - val numberAttempts = 300 - var attemptCount = 0 - while(true) { - try { - connectivityManager.requestNetwork(networkRequest, networkCallback, handler) - break - } catch (e: SecurityException) { - Log.e(TAG, "Failed to bind network listener: $e") - // Android 11 bug: https://issuetracker.google.com/issues/175055271 - if (e.message?.startsWith("Package android does not belong to") == true) { - if (++attemptCount > numberAttempts) { - throw e - } - delay(1000) - continue - } else { - throw e - } - } - } - } + connectivityManager.requestNetwork(networkRequest, networkCallback) isListenerBound = true } diff --git a/client/android/utils/src/main/kotlin/net/TrafficStats.kt b/client/android/utils/src/main/kotlin/net/TrafficStats.kt index 170d164e..f5a44bec 100644 --- a/client/android/utils/src/main/kotlin/net/TrafficStats.kt +++ b/client/android/utils/src/main/kotlin/net/TrafficStats.kt @@ -1,7 +1,6 @@ package org.amnezia.vpn.util.net import android.net.TrafficStats -import android.os.Build import android.os.Process import android.os.SystemClock import kotlin.math.roundToLong @@ -17,18 +16,12 @@ class TrafficStats { private var lastTrafficData = TrafficData.ZERO private var lastTimestamp = 0L - private val getTrafficDataCompat: () -> TrafficData = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - val iface = "tun0" - fun(): TrafficData { - return TrafficData(TrafficStats.getRxBytes(iface), TrafficStats.getTxBytes(iface)) - } - } else { - val uid = Process.myUid() - fun(): TrafficData { - return TrafficData(TrafficStats.getUidRxBytes(uid), TrafficStats.getUidTxBytes(uid)) - } + private val getTrafficDataCompat: () -> TrafficData = run { + val uid = Process.myUid() + fun(): TrafficData { + return TrafficData(TrafficStats.getUidRxBytes(uid), TrafficStats.getUidTxBytes(uid)) } + } fun reset() { lastTrafficData = getTrafficDataCompat() diff --git a/client/cmake/android.cmake b/client/cmake/android.cmake index 34ca5bff..c96d9ab8 100644 --- a/client/cmake/android.cmake +++ b/client/cmake/android.cmake @@ -1,6 +1,6 @@ message("Client android ${CMAKE_ANDROID_ARCH_ABI} build") -set(APP_ANDROID_MIN_SDK 26) +set(APP_ANDROID_MIN_SDK 24) set(ANDROID_PLATFORM "android-${APP_ANDROID_MIN_SDK}" CACHE STRING "The minimum API level supported by the application or library" FORCE) diff --git a/client/platforms/ios/WGConfig.swift b/client/platforms/ios/WGConfig.swift index 537687f1..8f693387 100644 --- a/client/platforms/ios/WGConfig.swift +++ b/client/platforms/ios/WGConfig.swift @@ -46,59 +46,29 @@ struct WGConfig: Decodable { } var settings: String { - guard junkPacketCount != nil else { return "" } - - var settingsLines: [String] = [] - - // Required parameters when junkPacketCount is present - settingsLines.append("Jc = \(junkPacketCount!)") - settingsLines.append("Jmin = \(junkPacketMinSize!)") - settingsLines.append("Jmax = \(junkPacketMaxSize!)") - settingsLines.append("S1 = \(initPacketJunkSize!)") - settingsLines.append("S2 = \(responsePacketJunkSize!)") - - settingsLines.append("H1 = \(initPacketMagicHeader!)") - settingsLines.append("H2 = \(responsePacketMagicHeader!)") - settingsLines.append("H3 = \(underloadPacketMagicHeader!)") - settingsLines.append("H4 = \(transportPacketMagicHeader!)") - - // Optional parameters - only add if not nil and not empty - if let s3 = cookieReplyPacketJunkSize, !s3.isEmpty { - settingsLines.append("S3 = \(s3)") - } - if let s4 = transportPacketJunkSize, !s4.isEmpty { - settingsLines.append("S4 = \(s4)") - } - - if let i1 = specialJunk1, !i1.isEmpty { - settingsLines.append("I1 = \(i1)") - } - if let i2 = specialJunk2, !i2.isEmpty { - settingsLines.append("I2 = \(i2)") - } - if let i3 = specialJunk3, !i3.isEmpty { - settingsLines.append("I3 = \(i3)") - } - if let i4 = specialJunk4, !i4.isEmpty { - settingsLines.append("I4 = \(i4)") - } - if let i5 = specialJunk5, !i5.isEmpty { - settingsLines.append("I5 = \(i5)") - } - if let j1 = controlledJunk1, !j1.isEmpty { - settingsLines.append("J1 = \(j1)") - } - if let j2 = controlledJunk2, !j2.isEmpty { - settingsLines.append("J2 = \(j2)") - } - if let j3 = controlledJunk3, !j3.isEmpty { - settingsLines.append("J3 = \(j3)") - } - if let itime = specialHandshakeTimeout, !itime.isEmpty { - settingsLines.append("Itime = \(itime)") - } - - return settingsLines.joined(separator: "\n") + junkPacketCount == nil ? "" : + """ + Jc = \(junkPacketCount!) + Jmin = \(junkPacketMinSize!) + Jmax = \(junkPacketMaxSize!) + S1 = \(initPacketJunkSize!) + S2 = \(responsePacketJunkSize!) + S3 = \(cookieReplyPacketJunkSize!) + S4 = \(transportPacketJunkSize!) + H1 = \(initPacketMagicHeader!) + H2 = \(responsePacketMagicHeader!) + H3 = \(underloadPacketMagicHeader!) + H4 = \(transportPacketMagicHeader!) + I1 = \(specialJunk1!) + I2 = \(specialJunk2!) + I3 = \(specialJunk3!) + I4 = \(specialJunk4!) + I5 = \(specialJunk5!) + J1 = \(controlledJunk1!) + J2 = \(controlledJunk2!) + J3 = \(controlledJunk3!) + Itime = \(specialHandshakeTimeout!) + """ } var str: String { diff --git a/client/ui/controllers/api/apiConfigsController.cpp b/client/ui/controllers/api/apiConfigsController.cpp index 0f42beb7..0b0a9b92 100644 --- a/client/ui/controllers/api/apiConfigsController.cpp +++ b/client/ui/controllers/api/apiConfigsController.cpp @@ -221,6 +221,8 @@ namespace serverConfig[configKey::apiConfig] = apiConfig; + qDebug() << serverConfig; + return ErrorCode::NoError; } } diff --git a/client/ui/qml/Pages2/PageSettingsKillSwitch.qml b/client/ui/qml/Pages2/PageSettingsKillSwitch.qml index d6d73b20..ca1cd0d4 100644 --- a/client/ui/qml/Pages2/PageSettingsKillSwitch.qml +++ b/client/ui/qml/Pages2/PageSettingsKillSwitch.qml @@ -62,7 +62,8 @@ PageType { Layout.leftMargin: 16 Layout.rightMargin: 16 - enabled: SettingsController.isKillSwitchEnabled && !ConnectionController.isConnected + visible: false + // enabled: SettingsController.isKillSwitchEnabled && !ConnectionController.isConnected checked: !SettingsController.strictKillSwitchEnabled text: qsTr("Soft KillSwitch") @@ -73,7 +74,9 @@ PageType { } } - DividerType {} + DividerType { + visible: false + } VerticalRadioButton { id: strictKillSwitch @@ -81,9 +84,7 @@ PageType { Layout.leftMargin: 16 Layout.rightMargin: 16 - visible: false - enabled: false - // enabled: SettingsController.isKillSwitchEnabled && !ConnectionController.isConnected + enabled: SettingsController.isKillSwitchEnabled && !ConnectionController.isConnected checked: SettingsController.strictKillSwitchEnabled text: qsTr("Strict KillSwitch") @@ -105,9 +106,7 @@ PageType { } } - DividerType { - visible: false - } + DividerType {} LabelWithButtonType { Layout.topMargin: 32