Android project restructuring
This commit is contained in:
parent
bc68c487ee
commit
5a5ea4a018
17 changed files with 46 additions and 48 deletions
|
@ -28,7 +28,7 @@
|
|||
<!-- <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> -->
|
||||
|
||||
<application
|
||||
android:name=".qt.AmneziaApp"
|
||||
android:name=".AmneziaApplication"
|
||||
android:label="-- %%INSERT_APP_NAME%% --"
|
||||
android:allowNativeHeapPointerTagging="false"
|
||||
android:icon="@drawable/icon"
|
||||
|
@ -36,7 +36,7 @@
|
|||
android:theme="@style/Theme.AppCompat.NoActionBar">
|
||||
|
||||
<activity
|
||||
android:name=".qt.VPNActivity"
|
||||
android:name=".AmneziaActivity"
|
||||
android:configChanges="uiMode|screenSize|smallestScreenSize|screenLayout|orientation|density
|
||||
|fontScale|layoutDirection|locale|keyboard|keyboardHidden|navigation|mcc|mnc"
|
||||
android:launchMode="singleInstance"
|
||||
|
@ -48,7 +48,7 @@
|
|||
</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" />
|
||||
</intent-filter>
|
||||
|
||||
|
@ -62,11 +62,11 @@
|
|||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".qt.CameraActivity"
|
||||
android:name=".CameraActivity"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".qt.ImportConfigActivity"
|
||||
android:name=".ImportConfigActivity"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter android:label="AmneziaVPN">
|
||||
|
@ -122,7 +122,7 @@
|
|||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".VPNService"
|
||||
android:name=".AmneziaVpnService"
|
||||
android:process=":QtOnlyProcess"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||
android:foregroundServiceType="specialUse"
|
||||
|
@ -136,7 +136,7 @@
|
|||
</service>
|
||||
|
||||
<service
|
||||
android:name=".qt.VPNPermissionHelper"
|
||||
android:name=".VPNPermissionHelper"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:exported="true">
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
package org.amnezia.vpn.qt;
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.Manifest
|
||||
import android.content.ComponentName
|
||||
|
@ -19,7 +19,6 @@ import android.view.KeyEvent
|
|||
import android.widget.Toast
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.amnezia.vpn.VPNService
|
||||
import org.amnezia.vpn.VPNServiceBinder
|
||||
import org.amnezia.vpn.IMPORT_COMMAND_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 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 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 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()
|
||||
|
||||
companion object {
|
||||
private lateinit var instance: VPNActivity
|
||||
private lateinit var instance: AmneziaActivity
|
||||
|
||||
@JvmStatic fun getInstance(): VPNActivity {
|
||||
@JvmStatic fun getInstance(): AmneziaActivity {
|
||||
return instance
|
||||
}
|
||||
|
||||
@JvmStatic fun connectService() {
|
||||
VPNActivity.getInstance().initServiceConnection()
|
||||
getInstance().initServiceConnection()
|
||||
}
|
||||
|
||||
@JvmStatic fun startQrCodeReader() {
|
||||
VPNActivity.getInstance().startQrCodeActivity()
|
||||
getInstance().startQrCodeActivity()
|
||||
}
|
||||
|
||||
@JvmStatic fun sendToService(actionCode: Int, body: String) {
|
||||
VPNActivity.getInstance().dispatchParcel(actionCode, body)
|
||||
getInstance().dispatchParcel(actionCode, body)
|
||||
}
|
||||
|
||||
@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 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")
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +231,7 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
|||
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.
|
|
@ -1,4 +1,4 @@
|
|||
package org.amnezia.vpn.qt
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.content.res.Configuration
|
||||
// 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 android.app.Application
|
||||
|
||||
class AmneziaApp: org.qtproject.qt.android.bindings.QtApplication() {
|
||||
class AmneziaApplication: org.qtproject.qt.android.bindings.QtApplication() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
|
@ -46,11 +46,11 @@ import java.lang.Exception
|
|||
import android.net.VpnService as BaseVpnService
|
||||
|
||||
|
||||
class VPNService : BaseVpnService()/* , LocalDnsService.Interface */ {
|
||||
class AmneziaVpnService : BaseVpnService()/* , LocalDnsService.Interface */ {
|
||||
|
||||
// override val data = BaseService.Data(this)
|
||||
|
||||
/* override */ val tag: String get() = "VPNService"
|
||||
/* override */ val tag: String get() = "AmneziaVpnService"
|
||||
// override fun createNotification(profileName: String): ServiceNotification =
|
||||
// ServiceNotification(this, profileName, "service-vpn")
|
||||
|
||||
|
@ -119,7 +119,7 @@ class VPNService : BaseVpnService()/* , LocalDnsService.Interface */ {
|
|||
@JvmStatic
|
||||
fun startService(c: Context) {
|
||||
c.applicationContext.startService(
|
||||
Intent(c.applicationContext, VPNService::class.java).apply {
|
||||
Intent(c.applicationContext, AmneziaVpnService::class.java).apply {
|
||||
putExtra("startOnly", true)
|
||||
})
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.amnezia.vpn.qt
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
|
@ -1,4 +1,4 @@
|
|||
package org.amnezia.vpn.qt
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
|
@ -14,10 +14,7 @@ import androidx.core.content.ContextCompat
|
|||
|
||||
import java.io.*
|
||||
|
||||
import org.amnezia.vpn.R
|
||||
|
||||
|
||||
const val INTENT_ACTION_IMPORT_CONFIG = "org.amnezia.vpn.qt.IMPORT_CONFIG"
|
||||
const val INTENT_ACTION_IMPORT_CONFIG = "org.amnezia.vpn.IMPORT_CONFIG"
|
||||
|
||||
class ImportConfigActivity : Activity() {
|
||||
|
||||
|
@ -40,7 +37,7 @@ class ImportConfigActivity : Activity() {
|
|||
return
|
||||
}
|
||||
|
||||
val activityIntent = Intent(applicationContext, VPNActivity::class.java)
|
||||
val activityIntent = Intent(applicationContext, AmneziaActivity::class.java)
|
||||
activityIntent.action = INTENT_ACTION_IMPORT_CONFIG
|
||||
activityIntent.addCategory("android.intent.category.DEFAULT")
|
||||
activityIntent.putExtra("CONFIG", config)
|
|
@ -47,9 +47,8 @@ import java.io.FileDescriptor
|
|||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
class NetworkState(var service: VPNService) {
|
||||
private var mService: VPNService = service
|
||||
class NetworkState(var service: AmneziaVpnService) {
|
||||
private var mService: AmneziaVpnService = service
|
||||
var mCurrentContext: Context = service
|
||||
private val tag = "NetworkState"
|
||||
private var active = false
|
||||
|
|
|
@ -72,7 +72,7 @@ object NotificationUtil {
|
|||
* Creates a new Notification using the current set of Strings
|
||||
* Shows the notification in the given {context}
|
||||
*/
|
||||
fun show(service: VPNService) {
|
||||
fun show(service: AmneziaVpnService) {
|
||||
sNotificationBuilder = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID)
|
||||
sCurrentContext = service
|
||||
val notificationManager: NotificationManager =
|
||||
|
@ -96,7 +96,7 @@ object NotificationUtil {
|
|||
val header = "" + prefs.getString("fallbackNotificationHeader", "Amnezia VPN")
|
||||
|
||||
// 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 intent = Intent(service, activity)
|
||||
val pendingIntent = PendingIntent.getActivity(service, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
|
|
@ -32,10 +32,10 @@ import net.openvpn.ovpn3.ClientAPI_TransportStats
|
|||
|
||||
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 var mAlreadyInitialised = false
|
||||
private var mService: VPNService = service
|
||||
private var mService: AmneziaVpnService = service
|
||||
|
||||
private var bytesInIndex = -1
|
||||
private var bytesOutIndex = -1
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
package org.amnezia.vpn.qt;
|
||||
package org.amnezia.vpn;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
|
@ -2,11 +2,10 @@
|
|||
* 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/. */
|
||||
|
||||
package org.amnezia.vpn.qt
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.os.Binder
|
||||
import android.os.Parcel
|
||||
import android.util.Log
|
||||
|
||||
const val permissionRequired = 6
|
||||
|
||||
|
@ -14,13 +13,13 @@ class VPNClientBinder() : Binder() {
|
|||
|
||||
override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
|
||||
if (code == permissionRequired) {
|
||||
VPNActivity.getInstance().onPermissionRequest(code, data)
|
||||
AmneziaActivity.getInstance().onPermissionRequest(code, data)
|
||||
return true
|
||||
}
|
||||
|
||||
val buffer = data.createByteArray()
|
||||
val stringData = buffer?.let { String(it) }
|
||||
VPNActivity.getInstance().onServiceMessage(code, stringData)
|
||||
AmneziaActivity.getInstance().onServiceMessage(code, stringData)
|
||||
|
||||
return true
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
package org.amnezia.vpn.qt
|
||||
package org.amnezia.vpn
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
|
@ -11,7 +11,7 @@ import com.wireguard.config.*
|
|||
import org.json.JSONObject
|
||||
import java.lang.Exception
|
||||
|
||||
class VPNServiceBinder(service: VPNService) : Binder() {
|
||||
class VPNServiceBinder(service: AmneziaVpnService) : Binder() {
|
||||
|
||||
private val mService = service
|
||||
private val tag = "VPNServiceBinder"
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package org.amnezia.vpn.qt
|
||||
|
||||
object QtAndroidController {
|
||||
}
|
|
@ -21,7 +21,7 @@ namespace
|
|||
{
|
||||
AndroidController *s_instance = nullptr;
|
||||
|
||||
constexpr auto PERMISSIONHELPER_CLASS = "org/amnezia/vpn/qt/VPNPermissionHelper";
|
||||
constexpr auto PERMISSIONHELPER_CLASS = "org/amnezia/vpn/VPNPermissionHelper";
|
||||
} // namespace
|
||||
|
||||
AndroidController::AndroidController() : QObject()
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace
|
||||
{
|
||||
AndroidVPNActivity *s_instance = nullptr;
|
||||
constexpr auto CLASSNAME = "org.amnezia.vpn.qt.VPNActivity";
|
||||
constexpr auto CLASSNAME = "org.amnezia.vpn.AmneziaActivity";
|
||||
}
|
||||
|
||||
AndroidVPNActivity::AndroidVPNActivity()
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace
|
|||
#endif
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
constexpr auto AndroidCameraActivity = "org.amnezia.vpn.qt.CameraActivity";
|
||||
constexpr auto AndroidCameraActivity = "org.amnezia.vpn.CameraActivity";
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue