parent
f6175c2c69
commit
3e02dfef63
22 changed files with 577 additions and 154 deletions
|
|
@ -143,7 +143,7 @@ class AmneziaActivity : QtActivity() {
|
|||
*/
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Log.v(TAG, "Create Amnezia activity: $intent")
|
||||
Log.d(TAG, "Create Amnezia activity: $intent")
|
||||
mainScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||
vpnServiceMessenger = IpcMessenger(
|
||||
onDeadObjectException = ::doUnbindService,
|
||||
|
|
@ -154,7 +154,7 @@ class AmneziaActivity : QtActivity() {
|
|||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
Log.v(TAG, "onNewIntent: $intent")
|
||||
Log.d(TAG, "onNewIntent: $intent")
|
||||
intent?.let(::processIntent)
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +174,7 @@ class AmneziaActivity : QtActivity() {
|
|||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
Log.v(TAG, "Start Amnezia activity")
|
||||
Log.d(TAG, "Start Amnezia activity")
|
||||
mainScope.launch {
|
||||
qtInitialized.await()
|
||||
doBindService()
|
||||
|
|
@ -182,13 +182,13 @@ class AmneziaActivity : QtActivity() {
|
|||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.v(TAG, "Stop Amnezia activity")
|
||||
Log.d(TAG, "Stop Amnezia activity")
|
||||
doUnbindService()
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.v(TAG, "Destroy Amnezia activity")
|
||||
Log.d(TAG, "Destroy Amnezia activity")
|
||||
mainScope.cancel()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ class AmneziaActivity : QtActivity() {
|
|||
CHECK_VPN_PERMISSION_ACTION_CODE -> {
|
||||
when (resultCode) {
|
||||
RESULT_OK -> {
|
||||
Log.v(TAG, "Vpn permission granted")
|
||||
Log.d(TAG, "Vpn permission granted")
|
||||
Toast.makeText(this, "Vpn permission granted", Toast.LENGTH_LONG).show()
|
||||
checkVpnPermissionCallbacks?.run { onSuccess() }
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ class AmneziaActivity : QtActivity() {
|
|||
*/
|
||||
@MainThread
|
||||
private fun doBindService() {
|
||||
Log.v(TAG, "Bind service")
|
||||
Log.d(TAG, "Bind service")
|
||||
Intent(this, AmneziaVpnService::class.java).also {
|
||||
bindService(it, serviceConnection, BIND_ABOVE_CLIENT)
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ class AmneziaActivity : QtActivity() {
|
|||
@MainThread
|
||||
private fun doUnbindService() {
|
||||
if (isInBoundState) {
|
||||
Log.v(TAG, "Unbind service")
|
||||
Log.d(TAG, "Unbind service")
|
||||
isWaitingStatus = true
|
||||
QtAndroidController.onServiceDisconnected()
|
||||
vpnServiceMessenger.reset()
|
||||
|
|
@ -286,7 +286,7 @@ class AmneziaActivity : QtActivity() {
|
|||
|
||||
@MainThread
|
||||
private fun checkVpnPermission(onSuccess: () -> Unit, onFail: () -> Unit) {
|
||||
Log.v(TAG, "Check VPN permission")
|
||||
Log.d(TAG, "Check VPN permission")
|
||||
VpnService.prepare(applicationContext)?.let {
|
||||
checkVpnPermissionCallbacks = CheckVpnPermissionCallbacks(onSuccess, onFail)
|
||||
startActivityForResult(it, CHECK_VPN_PERMISSION_ACTION_CODE)
|
||||
|
|
@ -307,7 +307,7 @@ class AmneziaActivity : QtActivity() {
|
|||
}
|
||||
|
||||
private fun connectToVpn(vpnConfig: String) {
|
||||
Log.v(TAG, "Connect to VPN")
|
||||
Log.d(TAG, "Connect to VPN")
|
||||
vpnServiceMessenger.send {
|
||||
Action.CONNECT.packToMessage {
|
||||
putString(VPN_CONFIG, vpnConfig)
|
||||
|
|
@ -316,7 +316,7 @@ class AmneziaActivity : QtActivity() {
|
|||
}
|
||||
|
||||
private fun startVpnService(vpnConfig: String) {
|
||||
Log.v(TAG, "Start VPN service")
|
||||
Log.d(TAG, "Start VPN service")
|
||||
Intent(this, AmneziaVpnService::class.java).apply {
|
||||
putExtra(VPN_CONFIG, vpnConfig)
|
||||
}.also {
|
||||
|
|
@ -325,7 +325,7 @@ class AmneziaActivity : QtActivity() {
|
|||
}
|
||||
|
||||
private fun disconnectFromVpn() {
|
||||
Log.v(TAG, "Disconnect from VPN")
|
||||
Log.d(TAG, "Disconnect from VPN")
|
||||
vpnServiceMessenger.send(Action.DISCONNECT)
|
||||
}
|
||||
|
||||
|
|
@ -369,7 +369,7 @@ class AmneziaActivity : QtActivity() {
|
|||
|
||||
@Suppress("unused")
|
||||
fun saveFile(fileName: String, data: String) {
|
||||
Log.v(TAG, "Save file $fileName")
|
||||
Log.d(TAG, "Save file $fileName")
|
||||
mainScope.launch {
|
||||
tmpFileContentToSave = data
|
||||
|
||||
|
|
@ -397,7 +397,7 @@ class AmneziaActivity : QtActivity() {
|
|||
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
Log.d(TAG, "File mimyType filter: $mimeTypes")
|
||||
Log.v(TAG, "File mimyType filter: $mimeTypes")
|
||||
when (mimeTypes.size) {
|
||||
1 -> type = mimeTypes.first()
|
||||
|
||||
|
|
@ -416,13 +416,6 @@ class AmneziaActivity : QtActivity() {
|
|||
@Suppress("unused")
|
||||
fun setNotificationText(title: String, message: String, timerSec: Int) {
|
||||
Log.v(TAG, "Set notification text")
|
||||
Log.w(TAG, "Not yet implemented")
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun cleanupLogs() {
|
||||
Log.v(TAG, "Cleanup logs")
|
||||
Log.w(TAG, "Not yet implemented")
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
|
|
@ -432,4 +425,29 @@ class AmneziaActivity : QtActivity() {
|
|||
startActivity(it)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun setSaveLogs(enabled: Boolean) {
|
||||
Log.d(TAG, "Set save logs: $enabled")
|
||||
mainScope.launch {
|
||||
Log.saveLogs = enabled
|
||||
vpnServiceMessenger.send {
|
||||
Action.SET_SAVE_LOGS.packToMessage {
|
||||
putBoolean(SAVE_LOGS, enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun exportLogsFile(fileName: String) {
|
||||
Log.v(TAG, "Export logs file")
|
||||
saveFile(fileName, Log.getLogs())
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun clearLogs() {
|
||||
Log.v(TAG, "Clear logs")
|
||||
Log.clearLogs()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue