Android project restructuring

This commit is contained in:
albexk 2023-11-16 20:16:28 +03:00
parent bc68c487ee
commit 5a5ea4a018
17 changed files with 46 additions and 48 deletions

View file

@ -28,7 +28,7 @@
<!-- <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> --> <!-- <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> -->
<application <application
android:name=".qt.AmneziaApp" android:name=".AmneziaApplication"
android:label="-- %%INSERT_APP_NAME%% --" android:label="-- %%INSERT_APP_NAME%% --"
android:allowNativeHeapPointerTagging="false" android:allowNativeHeapPointerTagging="false"
android:icon="@drawable/icon" android:icon="@drawable/icon"
@ -36,7 +36,7 @@
android:theme="@style/Theme.AppCompat.NoActionBar"> android:theme="@style/Theme.AppCompat.NoActionBar">
<activity <activity
android:name=".qt.VPNActivity" android:name=".AmneziaActivity"
android:configChanges="uiMode|screenSize|smallestScreenSize|screenLayout|orientation|density android:configChanges="uiMode|screenSize|smallestScreenSize|screenLayout|orientation|density
|fontScale|layoutDirection|locale|keyboard|keyboardHidden|navigation|mcc|mnc" |fontScale|layoutDirection|locale|keyboard|keyboardHidden|navigation|mcc|mnc"
android:launchMode="singleInstance" android:launchMode="singleInstance"
@ -48,7 +48,7 @@
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="org.amnezia.vpn.qt.IMPORT_CONFIG" /> <action android:name="org.amnezia.vpn.IMPORT_CONFIG" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
@ -62,11 +62,11 @@
</activity> </activity>
<activity <activity
android:name=".qt.CameraActivity" android:name=".CameraActivity"
android:exported="false" /> android:exported="false" />
<activity <activity
android:name=".qt.ImportConfigActivity" android:name=".ImportConfigActivity"
android:exported="true"> android:exported="true">
<intent-filter android:label="AmneziaVPN"> <intent-filter android:label="AmneziaVPN">
@ -122,7 +122,7 @@
</activity> </activity>
<service <service
android:name=".VPNService" android:name=".AmneziaVpnService"
android:process=":QtOnlyProcess" android:process=":QtOnlyProcess"
android:permission="android.permission.BIND_VPN_SERVICE" android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse" android:foregroundServiceType="specialUse"
@ -136,7 +136,7 @@
</service> </service>
<service <service
android:name=".qt.VPNPermissionHelper" android:name=".VPNPermissionHelper"
android:permission="android.permission.BIND_VPN_SERVICE" android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse" android:foregroundServiceType="specialUse"
android:exported="true"> android:exported="true">

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.amnezia.vpn.qt; package org.amnezia.vpn
import android.Manifest import android.Manifest
import android.content.ComponentName import android.content.ComponentName
@ -19,7 +19,6 @@ import android.view.KeyEvent
import android.widget.Toast import android.widget.Toast
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import org.amnezia.vpn.VPNService
import org.amnezia.vpn.VPNServiceBinder import org.amnezia.vpn.VPNServiceBinder
import org.amnezia.vpn.IMPORT_COMMAND_CODE import org.amnezia.vpn.IMPORT_COMMAND_CODE
import org.amnezia.vpn.IMPORT_ACTION_CODE import org.amnezia.vpn.IMPORT_ACTION_CODE
@ -27,7 +26,7 @@ import org.amnezia.vpn.IMPORT_CONFIG_KEY
import org.qtproject.qt.android.bindings.QtActivity import org.qtproject.qt.android.bindings.QtActivity
import java.io.* import java.io.*
class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() { class AmneziaActivity : org.qtproject.qt.android.bindings.QtActivity() {
private var configString: String? = null private var configString: String? = null
private var vpnServiceBinder: IBinder? = null private var vpnServiceBinder: IBinder? = null
@ -40,7 +39,7 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
} }
} }
private val TAG = "VPNActivity" private val TAG = "AmneziaActivity"
private val CAMERA_ACTION_CODE = 101 private val CAMERA_ACTION_CODE = 101
private val CREATE_FILE_ACTION_CODE = 102 private val CREATE_FILE_ACTION_CODE = 102
@ -50,26 +49,26 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
private val delayedCommands: ArrayList<Pair<Int, String>> = ArrayList() private val delayedCommands: ArrayList<Pair<Int, String>> = ArrayList()
companion object { companion object {
private lateinit var instance: VPNActivity private lateinit var instance: AmneziaActivity
@JvmStatic fun getInstance(): VPNActivity { @JvmStatic fun getInstance(): AmneziaActivity {
return instance return instance
} }
@JvmStatic fun connectService() { @JvmStatic fun connectService() {
VPNActivity.getInstance().initServiceConnection() getInstance().initServiceConnection()
} }
@JvmStatic fun startQrCodeReader() { @JvmStatic fun startQrCodeReader() {
VPNActivity.getInstance().startQrCodeActivity() getInstance().startQrCodeActivity()
} }
@JvmStatic fun sendToService(actionCode: Int, body: String) { @JvmStatic fun sendToService(actionCode: Int, body: String) {
VPNActivity.getInstance().dispatchParcel(actionCode, body) getInstance().dispatchParcel(actionCode, body)
} }
@JvmStatic fun saveFileAs(fileContent: String, suggestedName: String) { @JvmStatic fun saveFileAs(fileContent: String, suggestedName: String) {
VPNActivity.getInstance().saveFile(fileContent, suggestedName) getInstance().saveFile(fileContent, suggestedName)
} }
} }
@ -81,7 +80,7 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
val newIntent = intent val newIntent = intent
val newIntentAction: String? = newIntent.action val newIntentAction: String? = newIntent.action
if (newIntent != null && newIntentAction != null && newIntentAction == "org.amnezia.vpn.qt.IMPORT_CONFIG") { if (newIntent != null && newIntentAction != null && newIntentAction == "org.amnezia.vpn.IMPORT_CONFIG") {
configString = newIntent.getStringExtra("CONFIG") configString = newIntent.getStringExtra("CONFIG")
} }
} }
@ -232,7 +231,7 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
return return
} }
bindService(Intent(this, VPNService::class.java), connection, Context.BIND_AUTO_CREATE) bindService(Intent(this, AmneziaVpnService::class.java), connection, Context.BIND_AUTO_CREATE)
} }
// TODO: Move all ipc codes into a shared lib. // TODO: Move all ipc codes into a shared lib.

View file

@ -1,4 +1,4 @@
package org.amnezia.vpn.qt package org.amnezia.vpn
import android.content.res.Configuration import android.content.res.Configuration
// import org.amnezia.vpn.shadowsocks.core.Core // import org.amnezia.vpn.shadowsocks.core.Core
@ -7,7 +7,7 @@ import org.qtproject.qt.android.bindings.QtActivity
import org.qtproject.qt.android.bindings.QtApplication import org.qtproject.qt.android.bindings.QtApplication
import android.app.Application import android.app.Application
class AmneziaApp: org.qtproject.qt.android.bindings.QtApplication() { class AmneziaApplication: org.qtproject.qt.android.bindings.QtApplication() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()

View file

@ -46,11 +46,11 @@ import java.lang.Exception
import android.net.VpnService as BaseVpnService import android.net.VpnService as BaseVpnService
class VPNService : BaseVpnService()/* , LocalDnsService.Interface */ { class AmneziaVpnService : BaseVpnService()/* , LocalDnsService.Interface */ {
// override val data = BaseService.Data(this) // override val data = BaseService.Data(this)
/* override */ val tag: String get() = "VPNService" /* override */ val tag: String get() = "AmneziaVpnService"
// override fun createNotification(profileName: String): ServiceNotification = // override fun createNotification(profileName: String): ServiceNotification =
// ServiceNotification(this, profileName, "service-vpn") // ServiceNotification(this, profileName, "service-vpn")
@ -119,7 +119,7 @@ class VPNService : BaseVpnService()/* , LocalDnsService.Interface */ {
@JvmStatic @JvmStatic
fun startService(c: Context) { fun startService(c: Context) {
c.applicationContext.startService( c.applicationContext.startService(
Intent(c.applicationContext, VPNService::class.java).apply { Intent(c.applicationContext, AmneziaVpnService::class.java).apply {
putExtra("startOnly", true) putExtra("startOnly", true)
}) })
} }

View file

@ -1,4 +1,4 @@
package org.amnezia.vpn.qt package org.amnezia.vpn
import android.Manifest import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint

View file

@ -1,4 +1,4 @@
package org.amnezia.vpn.qt package org.amnezia.vpn
import android.Manifest import android.Manifest
import android.app.Activity import android.app.Activity
@ -14,10 +14,7 @@ import androidx.core.content.ContextCompat
import java.io.* import java.io.*
import org.amnezia.vpn.R const val INTENT_ACTION_IMPORT_CONFIG = "org.amnezia.vpn.IMPORT_CONFIG"
const val INTENT_ACTION_IMPORT_CONFIG = "org.amnezia.vpn.qt.IMPORT_CONFIG"
class ImportConfigActivity : Activity() { class ImportConfigActivity : Activity() {
@ -40,7 +37,7 @@ class ImportConfigActivity : Activity() {
return return
} }
val activityIntent = Intent(applicationContext, VPNActivity::class.java) val activityIntent = Intent(applicationContext, AmneziaActivity::class.java)
activityIntent.action = INTENT_ACTION_IMPORT_CONFIG activityIntent.action = INTENT_ACTION_IMPORT_CONFIG
activityIntent.addCategory("android.intent.category.DEFAULT") activityIntent.addCategory("android.intent.category.DEFAULT")
activityIntent.putExtra("CONFIG", config) activityIntent.putExtra("CONFIG", config)

View file

@ -47,9 +47,8 @@ import java.io.FileDescriptor
import java.io.IOException import java.io.IOException
import java.lang.Exception import java.lang.Exception
class NetworkState(var service: AmneziaVpnService) {
class NetworkState(var service: VPNService) { private var mService: AmneziaVpnService = service
private var mService: VPNService = service
var mCurrentContext: Context = service var mCurrentContext: Context = service
private val tag = "NetworkState" private val tag = "NetworkState"
private var active = false private var active = false

View file

@ -72,7 +72,7 @@ object NotificationUtil {
* Creates a new Notification using the current set of Strings * Creates a new Notification using the current set of Strings
* Shows the notification in the given {context} * Shows the notification in the given {context}
*/ */
fun show(service: VPNService) { fun show(service: AmneziaVpnService) {
sNotificationBuilder = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID) sNotificationBuilder = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID)
sCurrentContext = service sCurrentContext = service
val notificationManager: NotificationManager = val notificationManager: NotificationManager =
@ -96,7 +96,7 @@ object NotificationUtil {
val header = "" + prefs.getString("fallbackNotificationHeader", "Amnezia VPN") val header = "" + prefs.getString("fallbackNotificationHeader", "Amnezia VPN")
// Create the Intent that Should be Fired if the User Clicks the notification // Create the Intent that Should be Fired if the User Clicks the notification
val mainActivityName = "org.amnezia.vpn.qt.VPNActivity" val mainActivityName = "org.amnezia.vpn.AmneziaActivity"
val activity = Class.forName(mainActivityName) val activity = Class.forName(mainActivityName)
val intent = Intent(service, activity) val intent = Intent(service, activity)
val pendingIntent = PendingIntent.getActivity(service, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent = PendingIntent.getActivity(service, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)

View file

@ -32,10 +32,10 @@ import net.openvpn.ovpn3.ClientAPI_TransportStats
import java.lang.StringBuilder import java.lang.StringBuilder
class OpenVPNThreadv3(var service: VPNService): ClientAPI_OpenVPNClient(), Runnable { class OpenVPNThreadv3(var service: AmneziaVpnService): ClientAPI_OpenVPNClient(), Runnable {
private val tag = "OpenVPNThreadv3" private val tag = "OpenVPNThreadv3"
private var mAlreadyInitialised = false private var mAlreadyInitialised = false
private var mService: VPNService = service private var mService: AmneziaVpnService = service
private var bytesInIndex = -1 private var bytesInIndex = -1
private var bytesOutIndex = -1 private var bytesOutIndex = -1

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.amnezia.vpn.qt; package org.amnezia.vpn;
import android.Manifest; import android.Manifest;
import android.content.Context; import android.content.Context;

View file

@ -2,11 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.amnezia.vpn.qt package org.amnezia.vpn
import android.os.Binder import android.os.Binder
import android.os.Parcel import android.os.Parcel
import android.util.Log
const val permissionRequired = 6 const val permissionRequired = 6
@ -14,13 +13,13 @@ class VPNClientBinder() : Binder() {
override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean { override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
if (code == permissionRequired) { if (code == permissionRequired) {
VPNActivity.getInstance().onPermissionRequest(code, data) AmneziaActivity.getInstance().onPermissionRequest(code, data)
return true return true
} }
val buffer = data.createByteArray() val buffer = data.createByteArray()
val stringData = buffer?.let { String(it) } val stringData = buffer?.let { String(it) }
VPNActivity.getInstance().onServiceMessage(code, stringData) AmneziaActivity.getInstance().onServiceMessage(code, stringData)
return true return true
} }

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.amnezia.vpn.qt package org.amnezia.vpn
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent

View file

@ -11,7 +11,7 @@ import com.wireguard.config.*
import org.json.JSONObject import org.json.JSONObject
import java.lang.Exception import java.lang.Exception
class VPNServiceBinder(service: VPNService) : Binder() { class VPNServiceBinder(service: AmneziaVpnService) : Binder() {
private val mService = service private val mService = service
private val tag = "VPNServiceBinder" private val tag = "VPNServiceBinder"

View file

@ -0,0 +1,4 @@
package org.amnezia.vpn.qt
object QtAndroidController {
}

View file

@ -21,7 +21,7 @@ namespace
{ {
AndroidController *s_instance = nullptr; AndroidController *s_instance = nullptr;
constexpr auto PERMISSIONHELPER_CLASS = "org/amnezia/vpn/qt/VPNPermissionHelper"; constexpr auto PERMISSIONHELPER_CLASS = "org/amnezia/vpn/VPNPermissionHelper";
} // namespace } // namespace
AndroidController::AndroidController() : QObject() AndroidController::AndroidController() : QObject()

View file

@ -15,7 +15,7 @@
namespace namespace
{ {
AndroidVPNActivity *s_instance = nullptr; AndroidVPNActivity *s_instance = nullptr;
constexpr auto CLASSNAME = "org.amnezia.vpn.qt.VPNActivity"; constexpr auto CLASSNAME = "org.amnezia.vpn.AmneziaActivity";
} }
AndroidVPNActivity::AndroidVPNActivity() AndroidVPNActivity::AndroidVPNActivity()

View file

@ -50,7 +50,7 @@ namespace
#endif #endif
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
constexpr auto AndroidCameraActivity = "org.amnezia.vpn.qt.CameraActivity"; constexpr auto AndroidCameraActivity = "org.amnezia.vpn.CameraActivity";
#endif #endif
} // namespace } // namespace