diff --git a/android/app/build.gradle b/android/app/build.gradle index fdfed0bbc..f701e41e1 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -168,9 +168,9 @@ dependencies { androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2' androidTestImplementation 'androidx.test:rules:1.3.0-alpha03' - implementation 'network.mysterium:mobile-node:0.35.1-1snapshot-20200629T1411-494e56a1' + implementation 'network.mysterium:mobile-node:0.36.0' // Comment network.mysterium:mobile-node and replace with your local path to use local node build. - // implementation files('/Users/anjmao/go/src/github.com/mysteriumnetwork/node/build/package/Mysterium.aar') + //implementation files('/Users/zolia/golang/src/github.com/mysteriumnetwork/node/build/package/Mysterium.aar') } // Run this once to be able to run the application with BUCK diff --git a/android/app/src/main/java/network/mysterium/MainActivity.kt b/android/app/src/main/java/network/mysterium/MainActivity.kt index 44b299a66..7406f3936 100644 --- a/android/app/src/main/java/network/mysterium/MainActivity.kt +++ b/android/app/src/main/java/network/mysterium/MainActivity.kt @@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() { // start mobile node and initial data when network is available. CoroutineScope(Dispatchers.Main).launch { val coreService = deferredMysteriumCoreService.await() - coreService.startConnectivityChecker() + coreService.startConnectivityChecker(appContainer.nodeRepository) coreService.networkConnState().observe(this@MainActivity, Observer { CoroutineScope(Dispatchers.Main).launch { handleConnChange(it) } }) diff --git a/android/app/src/main/java/network/mysterium/service/core/MysteriumAndroidCoreService.kt b/android/app/src/main/java/network/mysterium/service/core/MysteriumAndroidCoreService.kt index baec6a341..b01b134f5 100644 --- a/android/app/src/main/java/network/mysterium/service/core/MysteriumAndroidCoreService.kt +++ b/android/app/src/main/java/network/mysterium/service/core/MysteriumAndroidCoreService.kt @@ -29,11 +29,11 @@ import android.os.IBinder import android.util.Log import androidx.lifecycle.MutableLiveData import kotlinx.coroutines.* +import mysterium.ConnectRequest import mysterium.MobileNode import mysterium.Mysterium import network.mysterium.NotificationFactory import network.mysterium.ui.ProposalViewItem -import network.mysterium.ui.ServiceType class NetworkConnState { var wifiConn = false @@ -102,7 +102,7 @@ class MysteriumAndroidCoreService : VpnService() { } } - private fun startConnectivityChecker(ctx: Context, onChange: (netState: NetworkConnState) -> Unit) { + private fun startConnectivityChecker(ctx: Context, onChange: (netState: NetworkConnState) -> Unit, nodeRepository: NodeRepository) { val connectivityManager = ctx.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val wifiManager = ctx.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager @@ -136,6 +136,16 @@ class MysteriumAndroidCoreService : VpnService() { CoroutineScope(Dispatchers.Main).launch { netConnState.value = newValue } + if (activeProposal != null) { + val req = ConnectRequest() + + req.identityAddress = nodeRepository.getIdentity().address + req.providerID = activeProposal!!.providerID + req.serviceType = activeProposal!!.serviceType.type + req.forceReconnect = true + Log.i(TAG, "Reconnecting identity ${req.identityAddress} to provider ${req.providerID} with service ${req.serviceType}") + nodeRepository.reconnect(req) + } } } catch (e: Exception) { Log.e(TAG, "Failed to check network connection state", e) @@ -172,9 +182,9 @@ class MysteriumAndroidCoreService : VpnService() { return netConnState } - override fun startConnectivityChecker() { - startConnectivityChecker(applicationContext) { - } + override fun startConnectivityChecker(nodeRepository: NodeRepository) { + startConnectivityChecker(applicationContext, { + }, nodeRepository) } override fun startNode(): MobileNode { diff --git a/android/app/src/main/java/network/mysterium/service/core/MysteriumCoreService.kt b/android/app/src/main/java/network/mysterium/service/core/MysteriumCoreService.kt index 0c1cadce3..85982ee3f 100644 --- a/android/app/src/main/java/network/mysterium/service/core/MysteriumCoreService.kt +++ b/android/app/src/main/java/network/mysterium/service/core/MysteriumCoreService.kt @@ -29,7 +29,7 @@ interface MysteriumCoreService : IBinder { fun stopNode() - fun startConnectivityChecker() + fun startConnectivityChecker(nodeRepository: NodeRepository) fun networkConnState(): MutableLiveData diff --git a/android/app/src/main/java/network/mysterium/service/core/NodeRepository.kt b/android/app/src/main/java/network/mysterium/service/core/NodeRepository.kt index a2912eeaa..4b6b40be5 100644 --- a/android/app/src/main/java/network/mysterium/service/core/NodeRepository.kt +++ b/android/app/src/main/java/network/mysterium/service/core/NodeRepository.kt @@ -161,6 +161,17 @@ class NodeRepository(private val deferredNode: DeferredNode) { } } + // Reconnect to VPN service. + suspend fun reconnect(req: ConnectRequest) = withContext(Dispatchers.IO) { + val res = deferredNode.await().reconnect(req) ?: return@withContext + + when(res.errorCode) { + "InvalidProposal" -> throw ConnectInvalidProposalException(res.errorMessage) + "InsufficientBalance" -> throw ConnectInsufficientBalanceException(res.errorMessage) + "Unknown" -> throw ConnectUnknownException(res.errorMessage) + } + } + // Disconnect from VPN service. suspend fun disconnect() = withContext(Dispatchers.IO) { deferredNode.await().disconnect() diff --git a/android/app/src/main/java/network/mysterium/ui/PriceUtils.kt b/android/app/src/main/java/network/mysterium/ui/PriceUtils.kt index a8c4c6982..a6117c6fb 100644 --- a/android/app/src/main/java/network/mysterium/ui/PriceUtils.kt +++ b/android/app/src/main/java/network/mysterium/ui/PriceUtils.kt @@ -1,5 +1,6 @@ package network.mysterium.ui +import android.util.Log import network.mysterium.service.core.ProposalPaymentMethod import network.mysterium.service.core.ProposalPaymentMoney import java.text.DecimalFormat @@ -20,7 +21,7 @@ object PriceUtils { ) } - val bytesInGiB = 1024 * 1024 * 1024 + private const val bytesInGiB = 1024 * 1024 * 1024 fun pricePerGiB(pm: ProposalPaymentMethod?): ProposalPaymentMoney { if (pm == null || pm.rate.perSeconds == 0L) { @@ -31,8 +32,10 @@ object PriceUtils { return ProposalPaymentMoney(amount = 0.0, currency = currency) } + var a = if (pm.rate.perBytes > 0L) (bytesInGiB / pm.rate.perBytes) * pm.price.amount else 0.0 + return ProposalPaymentMoney( - amount = (bytesInGiB / pm.rate.perBytes) * pm.price.amount, + amount = a, currency = pm.price.currency ) } diff --git a/fastlane/android_version_code b/fastlane/android_version_code index 98aa94b45..d1306cef3 100644 --- a/fastlane/android_version_code +++ b/fastlane/android_version_code @@ -1 +1 @@ -107071 +107072