Update dependencies and refine code style

This commit is contained in:
Mygod
2019-09-19 10:35:51 +08:00
parent 5e2aeef1d2
commit 650b06beae
16 changed files with 105 additions and 42 deletions

View File

@@ -13,8 +13,8 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.22.0' classpath 'com.github.ben-manes:gradle-versions-plugin:0.25.0'
classpath 'com.google.gms:google-services:4.3.1' classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.31.0' classpath 'io.fabric.tools:gradle:1.31.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
} }

View File

@@ -1,5 +1,4 @@
# https://github.com/arturbosch/detekt/blob/RC9.2/detekt-cli/src/main/resources/default-detekt-config.yml # https://github.com/arturbosch/detekt/blob/1.0.1/detekt-cli/src/main/resources/default-detekt-config.yml
autoCorrect: true
comments: comments:
active: false active: false
@@ -17,14 +16,16 @@ complexity:
active: true active: true
threshold: 10 threshold: 10
ignoreSingleWhenExpression: false ignoreSingleWhenExpression: false
ignoreSimpleWhenEntries: false
LabeledExpression: LabeledExpression:
active: false active: false
ignoredLabels: ""
LargeClass: LargeClass:
active: true active: true
threshold: 150 threshold: 600
LongMethod: LongMethod:
active: true active: true
threshold: 20 threshold: 60
LongParameterList: LongParameterList:
active: true active: true
threshold: 6 threshold: 6
@@ -36,12 +37,14 @@ complexity:
threshold: 4 threshold: 4
StringLiteralDuplication: StringLiteralDuplication:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
threshold: 3 threshold: 3
ignoreAnnotation: true ignoreAnnotation: true
excludeStringsWithLessThan5Characters: true excludeStringsWithLessThan5Characters: true
ignoreStringsRegex: '$^' ignoreStringsRegex: '$^'
TooManyFunctions: TooManyFunctions:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
thresholdInFiles: 11 thresholdInFiles: 11
thresholdInClasses: 11 thresholdInClasses: 11
thresholdInInterfaces: 11 thresholdInInterfaces: 11
@@ -49,6 +52,7 @@ complexity:
thresholdInEnums: 11 thresholdInEnums: 11
ignoreDeprecated: true ignoreDeprecated: true
ignorePrivate: false ignorePrivate: false
ignoreOverridden: true
empty-blocks: empty-blocks:
active: true active: true
@@ -69,7 +73,7 @@ empty-blocks:
active: true active: true
EmptyFunctionBlock: EmptyFunctionBlock:
active: true active: true
ignoreOverriddenFunctions: false ignoreOverriddenFunctions: true
EmptyIfBlock: EmptyIfBlock:
active: true active: true
EmptyInitBlock: EmptyInitBlock:
@@ -90,6 +94,7 @@ exceptions:
methodNames: 'toString,hashCode,equals,finalize' methodNames: 'toString,hashCode,equals,finalize'
InstanceOfCheckForException: InstanceOfCheckForException:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
NotImplementedDeclaration: NotImplementedDeclaration:
active: true active: true
PrintStackTrace: PrintStackTrace:
@@ -100,6 +105,8 @@ exceptions:
active: true active: true
SwallowedException: SwallowedException:
active: true active: true
ignoredExceptionTypes: 'InterruptedException,NumberFormatException,ParseException,MalformedURLException'
allowedExceptionNameRegex: "^(_|(ignore|expected).*)"
ThrowingExceptionFromFinally: ThrowingExceptionFromFinally:
active: false active: false
ThrowingExceptionInMain: ThrowingExceptionInMain:
@@ -111,6 +118,7 @@ exceptions:
active: true active: true
TooGenericExceptionCaught: TooGenericExceptionCaught:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
exceptionNames: exceptionNames:
- ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException
- Error - Error
@@ -133,6 +141,9 @@ formatting:
active: true active: true
android: true android: true
autoCorrect: true autoCorrect: true
AnnotationOnSeparateLine:
active: true
autoCorrect: true
ChainWrapping: ChainWrapping:
active: true active: true
autoCorrect: true autoCorrect: true
@@ -155,6 +166,9 @@ formatting:
ModifierOrdering: ModifierOrdering:
active: true active: true
autoCorrect: true autoCorrect: true
MultiLineIfElse:
active: true
autoCorrect: true
NoBlankLineBeforeRbrace: NoBlankLineBeforeRbrace:
active: true active: true
autoCorrect: true autoCorrect: true
@@ -164,8 +178,6 @@ formatting:
NoEmptyClassBody: NoEmptyClassBody:
active: true active: true
autoCorrect: true autoCorrect: true
NoItParamInMultilineLambda:
active: false
NoLineBreakAfterElse: NoLineBreakAfterElse:
active: true active: true
autoCorrect: true autoCorrect: true
@@ -188,6 +200,9 @@ formatting:
autoCorrect: true autoCorrect: true
NoWildcardImports: NoWildcardImports:
active: false active: false
PackageName:
active: true
autoCorrect: true
ParameterListWrapping: ParameterListWrapping:
active: false active: false
SpacingAroundColon: SpacingAroundColon:
@@ -199,12 +214,18 @@ formatting:
SpacingAroundCurly: SpacingAroundCurly:
active: true active: true
autoCorrect: true autoCorrect: true
SpacingAroundDot:
active: true
autoCorrect: true
SpacingAroundKeyword: SpacingAroundKeyword:
active: true active: true
autoCorrect: true autoCorrect: true
SpacingAroundOperators: SpacingAroundOperators:
active: true active: true
autoCorrect: true autoCorrect: true
SpacingAroundParens:
active: true
autoCorrect: true
SpacingAroundRangeOperator: SpacingAroundRangeOperator:
active: true active: true
autoCorrect: true autoCorrect: true
@@ -217,56 +238,73 @@ naming:
ClassNaming: ClassNaming:
active: true active: true
classPattern: '[A-Z$][a-zA-Z0-9$]*' classPattern: '[A-Z$][a-zA-Z0-9$]*'
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
ConstructorParameterNaming: ConstructorParameterNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
parameterPattern: '[a-z][A-Za-z0-9]*' parameterPattern: '[a-z][A-Za-z0-9]*'
privateParameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^' excludeClassPattern: '$^'
EnumNaming: EnumNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*'
ForbiddenClassName: ForbiddenClassName:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
forbiddenName: '' forbiddenName: ''
FunctionMaxLength: FunctionMaxLength:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
maximumFunctionNameLength: 30 maximumFunctionNameLength: 30
FunctionMinLength: FunctionMinLength:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
minimumFunctionNameLength: 3 minimumFunctionNameLength: 3
FunctionNaming: FunctionNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
excludeClassPattern: '$^' excludeClassPattern: '$^'
ignoreOverridden: true ignoreOverridden: true
FunctionParameterNaming: FunctionParameterNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
parameterPattern: '[a-z][A-Za-z0-9]*' parameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^' excludeClassPattern: '$^'
ignoreOverriddenFunctions: true
InvalidPackageDeclaration:
active: true
rootPackage: ''
MatchingDeclarationName: MatchingDeclarationName:
active: true active: true
MemberNameEqualsClassName: MemberNameEqualsClassName:
active: false active: false
ObjectPropertyNaming: ObjectPropertyNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
constantPattern: '[A-Za-z][_A-Za-z0-9]*' constantPattern: '[A-Za-z][_A-Za-z0-9]*'
propertyPattern: '[A-Za-z][_A-Za-z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
privatePropertyPattern: '(_)?[A-Za-z][A-Za-z0-9]*' privatePropertyPattern: '(_)?[A-Za-z][_A-Za-z0-9]*'
PackageNaming: PackageNaming:
active: true active: true
packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
packagePattern: '^[a-z]+(\.[a-z][A-Za-z0-9]*)*$'
TopLevelPropertyNaming: TopLevelPropertyNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
constantPattern: '[A-Z][_A-Z0-9]*' constantPattern: '[A-Z][_A-Z0-9]*'
propertyPattern: '[A-Za-z][_A-Za-z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
privatePropertyPattern: '(_)?[A-Za-z][A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*'
VariableMaxLength: VariableMaxLength:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
maximumVariableNameLength: 64 maximumVariableNameLength: 64
VariableMinLength: VariableMinLength:
active: false active: false
VariableNaming: VariableNaming:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
variablePattern: '[a-z][A-Za-z0-9]*' variablePattern: '[a-z][A-Za-z0-9]*'
privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^' excludeClassPattern: '$^'
@@ -274,10 +312,14 @@ naming:
performance: performance:
active: true active: true
ArrayPrimitive:
active: true
ForEachOnRange: ForEachOnRange:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
SpreadOperator: SpreadOperator:
active: true active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
UnnecessaryTemporaryInstantiation: UnnecessaryTemporaryInstantiation:
active: true active: true
@@ -299,6 +341,10 @@ potential-bugs:
active: true active: true
LateinitUsage: LateinitUsage:
active: false active: false
MissingWhenCase:
active: false
RedundantElseInWhen:
active: true
UnconditionalJumpStatementInLoop: UnconditionalJumpStatementInLoop:
active: true active: true
UnreachableCode: UnreachableCode:
@@ -318,8 +364,14 @@ style:
active: true active: true
DataClassContainsFunctions: DataClassContainsFunctions:
active: false active: false
DataClassShouldBeImmutable:
active: false
EqualsNullCall: EqualsNullCall:
active: true active: true
EqualsOnSignatureLine:
active: true
ExplicitItLambdaParameter:
active: true
ExpressionBodySyntax: ExpressionBodySyntax:
active: true active: true
includeLineWrapping: false includeLineWrapping: false
@@ -331,10 +383,14 @@ style:
imports: '' imports: ''
ForbiddenVoid: ForbiddenVoid:
active: true active: true
ignoreOverridden: true
ignoreUsageInGenerics: false
FunctionOnlyReturningConstant: FunctionOnlyReturningConstant:
active: true active: true
ignoreOverridableFunction: true ignoreOverridableFunction: true
excludedFunctions: 'describeContents' excludedFunctions: 'describeContents'
LibraryCodeMustSpecifyReturnType:
active: true
LoopWithTooManyJumpStatements: LoopWithTooManyJumpStatements:
active: true active: true
maxJumpCount: 1 maxJumpCount: 1
@@ -363,7 +419,7 @@ style:
OptionalUnit: OptionalUnit:
active: true active: true
OptionalWhenBraces: OptionalWhenBraces:
active: false active: true
PreferToOverPairSyntax: PreferToOverPairSyntax:
active: false active: false
ProtectedMemberInFinalClass: ProtectedMemberInFinalClass:
@@ -383,9 +439,13 @@ style:
max: 2 max: 2
TrailingWhitespace: TrailingWhitespace:
active: true active: true
UnderscoresInNumericLiterals:
active: false
UnnecessaryAbstractClass: UnnecessaryAbstractClass:
active: true active: true
excludeAnnotatedClasses: "dagger.Module" excludeAnnotatedClasses: "dagger.Module"
UnnecessaryApply:
active: true
UnnecessaryInheritance: UnnecessaryInheritance:
active: true active: true
UnnecessaryLet: UnnecessaryLet:
@@ -396,14 +456,22 @@ style:
active: true active: true
UnusedImports: UnusedImports:
active: true active: true
UnusedPrivateClass:
active: true
UnusedPrivateMember: UnusedPrivateMember:
active: true active: true
allowedNames: "(_|ignored|expected|serialVersionUID)" allowedNames: "(_|ignored|expected|serialVersionUID)"
UseCheckOrError:
active: true
UseDataClass: UseDataClass:
active: false active: false
UseRequire:
active: true
UselessCallOnNotNull:
active: true
UtilityClassWithPublicConstructor: UtilityClassWithPublicConstructor:
active: true active: true
VarCouldBeVal: VarCouldBeVal:
active: false active: true
WildcardImport: WildcardImport:
active: false active: false

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

4
gradlew vendored
View File

@@ -125,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if $cygwin ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`

View File

@@ -11,9 +11,9 @@ if (!getGradle().getStartParameter().getTaskRequests().toString().contains("Fdro
def javaVersion = JavaVersion.VERSION_1_8 def javaVersion = JavaVersion.VERSION_1_8
def aux = [ def aux = [
'com.crashlytics.sdk.android:crashlytics:2.10.1', 'com.crashlytics.sdk.android:crashlytics:2.10.1',
'com.google.firebase:firebase-analytics:17.1.0', 'com.google.firebase:firebase-analytics:17.2.0',
] ]
def lifecycleVersion = '2.2.0-alpha03' def lifecycleVersion = '2.2.0-alpha05'
def roomVersion = '2.1.0' def roomVersion = '2.1.0'
android { android {
@@ -75,27 +75,27 @@ androidExtensions {
dependencies { dependencies {
kapt "androidx.room:room-compiler:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion"
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.browser:browser:1.2.0-alpha07' implementation 'androidx.browser:browser:1.2.0-alpha08'
implementation 'androidx.core:core-ktx:1.1.0-rc03' implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.emoji:emoji:1.0.0' implementation 'androidx.emoji:emoji:1.0.0'
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation 'androidx.preference:preference:1.1.0-rc01' implementation 'androidx.preference:preference:1.1.0'
implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-ktx:$roomVersion"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'com.android.billingclient:billing:2.0.3' implementation 'com.android.billingclient:billing:2.0.3'
implementation 'com.github.topjohnwu.libsu:core:2.5.0' implementation 'com.github.topjohnwu.libsu:core:2.5.1'
implementation 'com.google.android.material:material:1.1.0-alpha09' implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.linkedin.dexmaker:dexmaker:2.25.0' implementation 'com.linkedin.dexmaker:dexmaker:2.25.0'
implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0' implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0'
implementation 'net.glxn.qrgen:android:2.0' implementation 'net.glxn.qrgen:android:2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.2' implementation 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.1'
for (dep in aux) { for (dep in aux) {
freedomImplementation dep freedomImplementation dep
googleImplementation dep googleImplementation dep

View File

@@ -62,7 +62,7 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
fun start() = when (val other = active.putIfAbsentCompat(downstream, this)) { fun start() = when (val other = active.putIfAbsentCompat(downstream, this)) {
null -> initRouting() null -> initRouting()
this -> true // already started this -> true // already started
else -> throw IllegalStateException("Double routing detected for $downstream from $caller != ${other.caller}") else -> error("Double routing detected for $downstream from $caller != ${other.caller}")
} }
private fun initRouting() = try { private fun initRouting() = try {

View File

@@ -59,7 +59,7 @@ open class Client(val mac: Long, val iface: String) {
IpNeighbour.State.INCOMPLETE -> R.string.connected_state_incomplete IpNeighbour.State.INCOMPLETE -> R.string.connected_state_incomplete
IpNeighbour.State.VALID -> R.string.connected_state_valid IpNeighbour.State.VALID -> R.string.connected_state_valid
IpNeighbour.State.FAILED -> R.string.connected_state_failed IpNeighbour.State.FAILED -> R.string.connected_state_failed
else -> throw IllegalStateException("Invalid IpNeighbour.State: $state") else -> error("Invalid IpNeighbour.State: $state")
})) }))
} }
}.trimEnd() }.trimEnd()

View File

@@ -1,7 +1,6 @@
package be.mygod.vpnhotspot.client package be.mygod.vpnhotspot.client
import androidx.emoji.text.EmojiCompat import androidx.emoji.text.EmojiCompat
import java.lang.IllegalStateException
fun emojize(text: CharSequence?): CharSequence? = if (text == null) null else try { fun emojize(text: CharSequence?): CharSequence? = if (text == null) null else try {
EmojiCompat.get().process(text) EmojiCompat.get().process(text)

View File

@@ -27,7 +27,7 @@ import java.lang.reflect.InvocationTargetException
sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
TetheringManager.OnStartTetheringCallback { TetheringManager.OnStartTetheringCallback {
class ViewHolder(val binding: ListitemInterfaceBinding) : RecyclerView.ViewHolder(binding.root), class ViewHolder(private val binding: ListitemInterfaceBinding) : RecyclerView.ViewHolder(binding.root),
View.OnClickListener { View.OnClickListener {
init { init {
itemView.updatePaddingRelative(start = itemView.resources.getDimensionPixelOffset( itemView.updatePaddingRelative(start = itemView.resources.getDimensionPixelOffset(

View File

@@ -35,7 +35,6 @@ import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import timber.log.Timber import timber.log.Timber
import java.lang.IllegalArgumentException
import java.lang.reflect.InvocationTargetException import java.lang.reflect.InvocationTargetException
import java.net.NetworkInterface import java.net.NetworkInterface
import java.net.SocketException import java.net.SocketException
@@ -195,6 +194,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
CONFIGURE_AP -> if (resultCode == DialogInterface.BUTTON_POSITIVE) try { CONFIGURE_AP -> if (resultCode == DialogInterface.BUTTON_POSITIVE) try {
WifiApManager.configuration = configuration WifiApManager.configuration = configuration
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
Timber.d(e)
SmartSnackbar.make(R.string.configuration_rejected).show() SmartSnackbar.make(R.string.configuration_rejected).show()
} catch (e: InvocationTargetException) { } catch (e: InvocationTargetException) {
SmartSnackbar.make(e.targetException).show() SmartSnackbar.make(e.targetException).show()

View File

@@ -13,7 +13,6 @@ import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.util.broadcastReceiver import be.mygod.vpnhotspot.util.broadcastReceiver
import be.mygod.vpnhotspot.util.intentFilter import be.mygod.vpnhotspot.util.intentFilter
import timber.log.Timber import timber.log.Timber
import java.lang.IllegalArgumentException
@RequiresApi(28) @RequiresApi(28)
class TetherTimeoutMonitor(private val context: Context, private val handler: Handler, class TetherTimeoutMonitor(private val context: Context, private val handler: Handler,

View File

@@ -5,7 +5,6 @@ import android.net.LinkProperties
import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.App.Companion.app
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.lang.UnsupportedOperationException
import java.net.InetAddress import java.net.InetAddress
import java.util.* import java.util.*
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap

View File

@@ -3,7 +3,6 @@ package be.mygod.vpnhotspot.net.wifi
import android.net.wifi.WifiConfiguration import android.net.wifi.WifiConfiguration
import android.net.wifi.WifiManager import android.net.wifi.WifiManager
import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.App.Companion.app
import java.lang.IllegalArgumentException
object WifiApManager { object WifiApManager {
private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") } private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") }
@@ -13,8 +12,8 @@ object WifiApManager {
var configuration: WifiConfiguration var configuration: WifiConfiguration
get() = getWifiApConfiguration.invoke(app.wifi) as? WifiConfiguration ?: WifiConfiguration() get() = getWifiApConfiguration.invoke(app.wifi) as? WifiConfiguration ?: WifiConfiguration()
set(value) { set(value) {
if (setWifiApConfiguration.invoke(app.wifi, value) as? Boolean != true) { require(setWifiApConfiguration.invoke(app.wifi, value) as? Boolean == true) {
throw IllegalArgumentException("setWifiApConfiguration failed") "setWifiApConfiguration failed"
} }
} }

View File

@@ -7,7 +7,6 @@ import android.net.wifi.p2p.WifiP2pManager
import be.mygod.vpnhotspot.DebugHelper import be.mygod.vpnhotspot.DebugHelper
import com.android.dx.stock.ProxyBuilder import com.android.dx.stock.ProxyBuilder
import timber.log.Timber import timber.log.Timber
import java.lang.IllegalArgumentException
import java.lang.reflect.Proxy import java.lang.reflect.Proxy
object WifiP2pManagerHelper { object WifiP2pManagerHelper {
@@ -30,7 +29,7 @@ object WifiP2pManagerHelper {
listener: WifiP2pManager.ActionListener) { listener: WifiP2pManager.ActionListener) {
try { try {
setWifiP2pChannels.invoke(this, c, lc, oc, listener) setWifiP2pChannels.invoke(this, c, lc, oc, listener)
} catch (e: NoSuchMethodException) { } catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_setWifiP2pChannels") DebugHelper.logEvent("NoSuchMethod_setWifiP2pChannels")
listener.onFailure(UNSUPPORTED) listener.onFailure(UNSUPPORTED)
} }
@@ -46,7 +45,7 @@ object WifiP2pManagerHelper {
try { try {
WifiP2pManager::class.java.getDeclaredMethod("startWps", WifiP2pManager::class.java.getDeclaredMethod("startWps",
WifiP2pManager.Channel::class.java, WpsInfo::class.java, WifiP2pManager.ActionListener::class.java) WifiP2pManager.Channel::class.java, WpsInfo::class.java, WifiP2pManager.ActionListener::class.java)
} catch (e: NoSuchMethodException) { } catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_startWps") DebugHelper.logEvent("NoSuchMethod_startWps")
null null
} }
@@ -69,7 +68,7 @@ object WifiP2pManagerHelper {
listener: WifiP2pManager.ActionListener) { listener: WifiP2pManager.ActionListener) {
try { try {
deletePersistentGroup.invoke(this, c, netId, listener) deletePersistentGroup.invoke(this, c, netId, listener)
} catch (e: NoSuchMethodException) { } catch (_: NoSuchMethodException) {
DebugHelper.logEvent("NoSuchMethod_deletePersistentGroup") DebugHelper.logEvent("NoSuchMethod_deletePersistentGroup")
listener.onFailure(UNSUPPORTED) listener.onFailure(UNSUPPORTED)
} }

View File

@@ -7,7 +7,6 @@ import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.RepeaterService import be.mygod.vpnhotspot.RepeaterService
import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.util.RootSession
import java.io.File import java.io.File
import java.lang.IllegalStateException
/** /**
* This parser is based on: * This parser is based on:

View File

@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot.net.wifi.configuration package be.mygod.vpnhotspot.net.wifi.configuration
import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.content.ClipData import android.content.ClipData
import android.content.DialogInterface import android.content.DialogInterface
@@ -90,6 +91,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
override fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener) { override fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener) {
val activity = requireActivity() val activity = requireActivity()
@SuppressLint("InflateParams")
dialogView = activity.layoutInflater.inflate(R.layout.dialog_wifi_ap, null) dialogView = activity.layoutInflater.inflate(R.layout.dialog_wifi_ap, null)
setView(dialogView) setView(dialogView)
if (!arg.readOnly) setPositiveButton(R.string.wifi_save, listener) if (!arg.readOnly) setPositiveButton(R.string.wifi_save, listener)
@@ -103,8 +105,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
} }
onItemSelectedListener = object : AdapterView.OnItemSelectedListener { onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) = override fun onNothingSelected(parent: AdapterView<*>?) = error("Must select something")
throw IllegalStateException("Must select something")
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
dialogView.password_wrapper.isGone = position == WifiConfiguration.KeyMgmt.NONE dialogView.password_wrapper.isGone = position == WifiConfiguration.KeyMgmt.NONE
} }