diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3b3a465..f421fe8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -73,5 +73,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/freeturn/app/ProxyTileService.kt b/app/src/main/java/com/freeturn/app/ProxyTileService.kt new file mode 100644 index 0000000..efb7c87 --- /dev/null +++ b/app/src/main/java/com/freeturn/app/ProxyTileService.kt @@ -0,0 +1,61 @@ +package com.freeturn.app + +import android.content.Intent +import android.service.quicksettings.Tile +import android.service.quicksettings.TileService +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import android.os.Build +import androidx.annotation.RequiresApi + +@RequiresApi(Build.VERSION_CODES.N) +class ProxyTileService : TileService() { + + private var scope: CoroutineScope? = null + private var isProxyRunning = false + + override fun onStartListening() { + super.onStartListening() + scope = CoroutineScope(Dispatchers.Main + SupervisorJob()) + ProxyServiceState.isRunning.onEach { running -> + isProxyRunning = running + updateTileState() + }.launchIn(scope!!) + } + + override fun onStopListening() { + super.onStopListening() + scope?.cancel() + scope = null + } + + override fun onClick() { + super.onClick() + if (isProxyRunning) { + val intent = Intent(this, ProxyReceiver::class.java).apply { + action = "com.freeturn.app.STOP_PROXY" + } + sendBroadcast(intent) + } else { + val intent = Intent(this, ProxyReceiver::class.java).apply { + action = "com.freeturn.app.START_PROXY" + } + sendBroadcast(intent) + } + } + + private fun updateTileState() { + val tile = qsTile ?: return + if (isProxyRunning) { + tile.state = Tile.STATE_ACTIVE + } else { + tile.state = Tile.STATE_INACTIVE + } + tile.icon = android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_qs_tile_nearby) + tile.updateTile() + } +} diff --git a/app/src/main/jniLibs/arm64-v8a/libvkturn.so b/app/src/main/jniLibs/arm64-v8a/libfreeturn-1.0.1-android-arm64.so similarity index 67% rename from app/src/main/jniLibs/arm64-v8a/libvkturn.so rename to app/src/main/jniLibs/arm64-v8a/libfreeturn-1.0.1-android-arm64.so index f0edd22..59f64da 100644 Binary files a/app/src/main/jniLibs/arm64-v8a/libvkturn.so and b/app/src/main/jniLibs/arm64-v8a/libfreeturn-1.0.1-android-arm64.so differ diff --git a/app/src/main/res/drawable/ic_qs_tile_nearby.xml b/app/src/main/res/drawable/ic_qs_tile_nearby.xml new file mode 100644 index 0000000..f076380 --- /dev/null +++ b/app/src/main/res/drawable/ic_qs_tile_nearby.xml @@ -0,0 +1,14 @@ + + + + +