diff --git a/build.gradle b/build.gradle index c72dfe34..b6668a65 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.github.ben-manes.versions' buildscript { - ext.kotlinVersion = '1.3.30' + ext.kotlinVersion = '1.3.31' repositories { google() jcenter() @@ -12,7 +12,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0-rc03' + classpath 'com.android.tools.build:gradle:3.4.0' classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0' classpath 'com.google.gms:google-services:4.2.0' classpath 'io.fabric.tools:gradle:1.28.1' diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cb..5c2d1cf0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 51fb1c46..ee69dd68 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index af6708ff..b0d6d0ab 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index 0f8d5937..15e1ee37 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/mobile/build.gradle b/mobile/build.gradle index 553d9674..4a241049 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -19,8 +19,8 @@ android { minSdkVersion 21 targetSdkVersion 28 resConfigs "ru", "zh-rCN" - versionCode 200 - versionName "2.4.0" + versionCode 201 + versionName "2.4.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { @@ -68,28 +68,28 @@ def aux = [ 'com.google.firebase:firebase-core:16.0.8', ] def lifecycleVersion = '2.0.0' -def roomVersion = '2.1.0-alpha06' +def roomVersion = '2.1.0-alpha07' dependencies { - kapt "androidx.lifecycle:lifecycle-compiler:$lifecycleVersion" kapt "androidx.room:room-compiler:$roomVersion" implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.browser:browser:1.0.0' implementation 'androidx.core:core-ktx:1.0.1' implementation 'androidx.emoji:emoji:1.0.0' + implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" implementation 'androidx.preference:preference:1.1.0-alpha04' implementation "androidx.room:room-ktx:$roomVersion" implementation 'com.android.billingclient:billing:1.2.2' implementation 'com.github.luongvo:BadgeView:1.1.5' - implementation 'com.github.topjohnwu.libsu:core:2.4.0' + implementation 'com.github.topjohnwu.libsu:core:2.5.0' implementation 'com.google.android.material:material:1.0.0' implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.linkedin.dexmaker:dexmaker:2.25.0' implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0' implementation 'net.glxn.qrgen:android:2.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1' for (dep in aux) { freedomImplementation dep googleImplementation dep diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 2ec37e78..96e6e0b3 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -88,19 +88,15 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { } override fun onFailed(reason: Int) { - val message = getString(R.string.tethering_temp_hotspot_failure, - when (reason) { - WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL -> - getString(R.string.tethering_temp_hotspot_failure_no_channel) - WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC -> - getString(R.string.tethering_temp_hotspot_failure_generic) - WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE -> - getString(R.string.tethering_temp_hotspot_failure_incompatible_mode) - WifiManager.LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED -> - getString(R.string.tethering_temp_hotspot_failure_tethering_disallowed) - else -> getString(R.string.failure_reason_unknown, reason) - }) - SmartSnackbar.make(message).show() + SmartSnackbar.make(getString(R.string.tethering_temp_hotspot_failure, when (reason) { + ERROR_NO_CHANNEL -> getString(R.string.tethering_temp_hotspot_failure_no_channel) + ERROR_GENERIC -> getString(R.string.tethering_temp_hotspot_failure_generic) + ERROR_INCOMPATIBLE_MODE -> getString(R.string.tethering_temp_hotspot_failure_incompatible_mode) + ERROR_TETHERING_DISALLOWED -> { + getString(R.string.tethering_temp_hotspot_failure_tethering_disallowed) + } + else -> getString(R.string.failure_reason_unknown, reason) + })).show() startFailure() } }, null) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index b803cd4f..7c0b7552 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -36,7 +36,7 @@ class TetheringService : IpNeighbourMonitoringService() { RoutingManager(caller, downstream, TetherType.ofInterface(downstream).isWifi) { override fun Routing.configure() { forward() - masquerade(RoutingManager.masqueradeMode) + masquerade(masqueradeMode) if (app.pref.getBoolean("service.disableIpv6", true)) disableIpv6() commit() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index 3ca6a172..1363f14d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -9,9 +9,8 @@ import androidx.annotation.RequiresApi import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.core.view.updatePaddingRelative -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.OnLifecycleEvent +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.DebugHelper @@ -105,8 +104,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), fun updateErrorMessage(errored: List) { data.text = errored.filter { TetherType.ofInterface(it) == tetherType }.joinToString("\n") { "$it: " + try { - val error = TetheringManager.getLastTetherError(it) - when (error) { + when (val error = TetheringManager.getLastTetherError(it)) { TetheringManager.TETHER_ERROR_NO_ERROR -> "TETHER_ERROR_NO_ERROR" TetheringManager.TETHER_ERROR_UNKNOWN_IFACE -> "TETHER_ERROR_UNKNOWN_IFACE" TetheringManager.TETHER_ERROR_SERVICE_UNAVAIL -> "TETHER_ERROR_SERVICE_UNAVAIL" @@ -148,15 +146,14 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), override fun stop() = TetheringManager.stop(TetheringManager.TETHERING_USB) } @RequiresApi(24) - class Bluetooth(parent: TetheringFragment) : TetherManager(parent), LifecycleObserver { + class Bluetooth(parent: TetheringFragment) : TetherManager(parent), DefaultLifecycleObserver { private val tethering = BluetoothTethering(parent.requireContext()) { onTetheringStarted() } init { parent.lifecycle.addObserver(this) } - @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) - fun onDestroy() = tethering.close() + override fun onDestroy(owner: LifecycleOwner) = tethering.close() override val title get() = parent.getString(R.string.tethering_manage_bluetooth) override val tetherType get() = TetherType.BLUETOOTH diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt index 64078939..3bb1061e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt @@ -10,9 +10,8 @@ import androidx.annotation.RequiresApi import androidx.core.content.edit import androidx.core.content.getSystemService import androidx.core.os.BuildCompat -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.OnLifecycleEvent +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner import be.mygod.vpnhotspot.App.Companion.app /** @@ -70,7 +69,7 @@ class WifiDoubleLock(lockType: Int) : AutoCloseable { } class ActivityListener(private val activity: ComponentActivity) : - LifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener { + DefaultLifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener { private var keepScreenOn: Boolean = false set(value) { if (field == value) return @@ -89,8 +88,7 @@ class WifiDoubleLock(lockType: Int) : AutoCloseable { if (key == KEY) keepScreenOn = mode.keepScreenOn } - @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) - fun shutdown() = app.pref.unregisterOnSharedPreferenceChangeListener(this) + override fun onDestroy(owner: LifecycleOwner) = app.pref.unregisterOnSharedPreferenceChangeListener(this) } private val wifi = app.wifi.createWifiLock(lockType, "vpnhotspot:wifi").apply { acquire() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt index adaba02d..03a93f3d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt @@ -5,17 +5,15 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import androidx.fragment.app.Fragment -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.OnLifecycleEvent import kotlin.reflect.KClass /** * owner also needs to be Context/Fragment. */ class ServiceForegroundConnector(private val owner: LifecycleOwner, private val connection: ServiceConnection, - private val clazz: KClass) : LifecycleObserver { + private val clazz: KClass) : DefaultLifecycleObserver { init { owner.lifecycle.addObserver(this) } @@ -26,12 +24,10 @@ class ServiceForegroundConnector(private val owner: LifecycleOwner, private val else -> throw UnsupportedOperationException("Unsupported owner") } - @OnLifecycleEvent(Lifecycle.Event.ON_START) - fun onStart() { + override fun onStart(owner: LifecycleOwner) { val context = context context.bindService(Intent(context, clazz.java), connection, Context.BIND_AUTO_CREATE) } - @OnLifecycleEvent(Lifecycle.Event.ON_STOP) - fun onStop() = context.stopAndUnbind(connection) + override fun onStop(owner: LifecycleOwner) = context.stopAndUnbind(connection) } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt index e9fa604f..e3d056fe 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/SpanFormatter.kt @@ -59,9 +59,8 @@ object SpanFormatter { val argTerm = m.group(1)!! val modTerm = m.group(2) - val typeTerm = m.group(3) - val cookedArg = when (typeTerm) { + val cookedArg = when (val typeTerm = m.group(3)) { "%" -> "%" "n" -> "\n" else -> { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt b/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt index d10fc6c9..a4711418 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/widget/SmartSnackbar.kt @@ -5,9 +5,9 @@ import android.os.Looper import android.view.View import android.widget.Toast import androidx.annotation.StringRes +import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.OnLifecycleEvent +import androidx.lifecycle.LifecycleOwner import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.util.readableMessage import com.google.android.material.snackbar.Snackbar @@ -32,17 +32,15 @@ sealed class SmartSnackbar { }.readableMessage) } - class Register(lifecycle: Lifecycle, private val view: View) : LifecycleObserver { + class Register(lifecycle: Lifecycle, private val view: View) : DefaultLifecycleObserver { init { lifecycle.addObserver(this) } - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - fun onResume() { + override fun onResume(owner: LifecycleOwner) { holder = view } - @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) - fun onPause() { + override fun onPause(owner: LifecycleOwner) { if (holder === view) holder = null } }