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

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
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\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

View File

@@ -11,9 +11,9 @@ if (!getGradle().getStartParameter().getTaskRequests().toString().contains("Fdro
def javaVersion = JavaVersion.VERSION_1_8
def aux = [
'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'
android {
@@ -75,27 +75,27 @@ androidExtensions {
dependencies {
kapt "androidx.room:room-compiler:$roomVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.browser:browser:1.2.0-alpha07'
implementation 'androidx.core:core-ktx:1.1.0-rc03'
implementation 'androidx.browser:browser:1.2.0-alpha08'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.emoji:emoji:1.0.0'
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-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.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'com.android.billingclient:billing:2.0.3'
implementation 'com.github.topjohnwu.libsu:core:2.5.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'
implementation 'com.github.topjohnwu.libsu:core:2.5.1'
implementation 'com.google.android.material:material:1.1.0-alpha10'
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-jdk8:$kotlinVersion"
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) {
freedomImplementation 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)) {
null -> initRouting()
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 {

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.VALID -> R.string.connected_state_valid
IpNeighbour.State.FAILED -> R.string.connected_state_failed
else -> throw IllegalStateException("Invalid IpNeighbour.State: $state")
else -> error("Invalid IpNeighbour.State: $state")
}))
}
}.trimEnd()

View File

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

View File

@@ -27,7 +27,7 @@ import java.lang.reflect.InvocationTargetException
sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
TetheringManager.OnStartTetheringCallback {
class ViewHolder(val binding: ListitemInterfaceBinding) : RecyclerView.ViewHolder(binding.root),
class ViewHolder(private val binding: ListitemInterfaceBinding) : RecyclerView.ViewHolder(binding.root),
View.OnClickListener {
init {
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.withContext
import timber.log.Timber
import java.lang.IllegalArgumentException
import java.lang.reflect.InvocationTargetException
import java.net.NetworkInterface
import java.net.SocketException
@@ -195,6 +194,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
CONFIGURE_AP -> if (resultCode == DialogInterface.BUTTON_POSITIVE) try {
WifiApManager.configuration = configuration
} catch (e: IllegalArgumentException) {
Timber.d(e)
SmartSnackbar.make(R.string.configuration_rejected).show()
} catch (e: InvocationTargetException) {
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.intentFilter
import timber.log.Timber
import java.lang.IllegalArgumentException
@RequiresApi(28)
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 kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.lang.UnsupportedOperationException
import java.net.InetAddress
import java.util.*
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.WifiManager
import be.mygod.vpnhotspot.App.Companion.app
import java.lang.IllegalArgumentException
object WifiApManager {
private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") }
@@ -13,8 +12,8 @@ object WifiApManager {
var configuration: WifiConfiguration
get() = getWifiApConfiguration.invoke(app.wifi) as? WifiConfiguration ?: WifiConfiguration()
set(value) {
if (setWifiApConfiguration.invoke(app.wifi, value) as? Boolean != true) {
throw IllegalArgumentException("setWifiApConfiguration failed")
require(setWifiApConfiguration.invoke(app.wifi, value) as? Boolean == true) {
"setWifiApConfiguration failed"
}
}

View File

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

View File

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

View File

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