Commit 26acea8e authored by Mygod's avatar Mygod

Fix code style issues

parent a7d77461
# https://github.com/arturbosch/detekt/blob/801994bd60cc759b181649356cea045b8125301b/detekt-cli/src/main/resources/default-detekt-config.yml # https://github.com/arturbosch/detekt/blob/RC6-4/detekt-cli/src/main/resources/default-detekt-config.yml
comments: comments:
active: false active: false
...@@ -7,7 +7,7 @@ complexity: ...@@ -7,7 +7,7 @@ complexity:
active: true active: true
ComplexCondition: ComplexCondition:
active: true active: true
threshold: 3 threshold: 4
ComplexInterface: ComplexInterface:
active: true active: true
threshold: 10 threshold: 10
...@@ -15,6 +15,7 @@ complexity: ...@@ -15,6 +15,7 @@ complexity:
ComplexMethod: ComplexMethod:
active: true active: true
threshold: 10 threshold: 10
ignoreSingleWhenExpression: false
LabeledExpression: LabeledExpression:
active: true active: true
LargeClass: LargeClass:
...@@ -25,31 +26,32 @@ complexity: ...@@ -25,31 +26,32 @@ complexity:
threshold: 20 threshold: 20
LongParameterList: LongParameterList:
active: true active: true
threshold: 5 threshold: 6
ignoreDefaultParameters: true ignoreDefaultParameters: true
MethodOverloading: MethodOverloading:
active: false active: false
NestedBlockDepth: NestedBlockDepth:
active: true active: true
threshold: 3 threshold: 4
StringLiteralDuplication: StringLiteralDuplication:
active: true active: true
threshold: 2 threshold: 3
ignoreAnnotation: true ignoreAnnotation: true
excludeStringsWithLessThan5Characters: true excludeStringsWithLessThan5Characters: true
ignoreStringsRegex: '$^' ignoreStringsRegex: '$^'
TooManyFunctions: TooManyFunctions:
active: true active: true
thresholdInFiles: 10 thresholdInFiles: 11
thresholdInClasses: 10 thresholdInClasses: 11
thresholdInInterfaces: 10 thresholdInInterfaces: 11
thresholdInObjects: 10 thresholdInObjects: 11
thresholdInEnums: 10 thresholdInEnums: 11
empty-blocks: empty-blocks:
active: true active: true
EmptyCatchBlock: EmptyCatchBlock:
active: false active: true
allowedExceptionNameRegex: "^(_|ignore|expected).*"
EmptyClassBlock: EmptyClassBlock:
active: true active: true
EmptyDefaultConstructor: EmptyDefaultConstructor:
...@@ -64,6 +66,7 @@ empty-blocks: ...@@ -64,6 +66,7 @@ empty-blocks:
active: true active: true
EmptyFunctionBlock: EmptyFunctionBlock:
active: true active: true
ignoreOverriddenFunctions: false
EmptyIfBlock: EmptyIfBlock:
active: true active: true
EmptyInitBlock: EmptyInitBlock:
...@@ -105,7 +108,7 @@ exceptions: ...@@ -105,7 +108,7 @@ exceptions:
active: true active: true
TooGenericExceptionCaught: TooGenericExceptionCaught:
active: true active: true
exceptions: exceptionNames:
- ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException
- Error - Error
- Exception - Exception
...@@ -116,10 +119,9 @@ exceptions: ...@@ -116,10 +119,9 @@ exceptions:
- Throwable - Throwable
TooGenericExceptionThrown: TooGenericExceptionThrown:
active: true active: true
exceptions: exceptionNames:
- Error - Error
- Exception - Exception
- NullPointerException
- Throwable - Throwable
- RuntimeException - RuntimeException
...@@ -143,6 +145,7 @@ naming: ...@@ -143,6 +145,7 @@ naming:
FunctionNaming: FunctionNaming:
active: true active: true
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
excludeClassPattern: '$^'
MatchingDeclarationName: MatchingDeclarationName:
active: true active: true
MemberNameEqualsClassName: MemberNameEqualsClassName:
...@@ -167,6 +170,7 @@ naming: ...@@ -167,6 +170,7 @@ naming:
active: true active: true
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: '$^'
performance: performance:
active: true active: true
...@@ -239,15 +243,17 @@ style: ...@@ -239,15 +243,17 @@ style:
maxLineLength: 120 maxLineLength: 120
excludePackageStatements: false excludePackageStatements: false
excludeImportStatements: false excludeImportStatements: false
MayBeConst:
active: true
ModifierOrder: ModifierOrder:
active: true active: true
NestedClassesVisibility: NestedClassesVisibility:
active: true active: true
NewLineAtEndOfFile: NewLineAtEndOfFile:
active: true active: true
OptionalAbstractKeyword: NoTabs:
active: true active: true
OptionalReturnKeyword: OptionalAbstractKeyword:
active: true active: true
OptionalUnit: OptionalUnit:
active: true active: true
...@@ -268,6 +274,8 @@ style: ...@@ -268,6 +274,8 @@ style:
ThrowsCount: ThrowsCount:
active: true active: true
max: 2 max: 2
TrailingWhitespace:
active: true
UnnecessaryAbstractClass: UnnecessaryAbstractClass:
active: true active: true
UnnecessaryInheritance: UnnecessaryInheritance:
...@@ -278,6 +286,8 @@ style: ...@@ -278,6 +286,8 @@ style:
active: true active: true
UnusedImports: UnusedImports:
active: true active: true
UnusedPrivateMember:
active: true
UseDataClass: UseDataClass:
active: false active: false
UtilityClassWithPublicConstructor: UtilityClassWithPublicConstructor:
......
...@@ -62,23 +62,21 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener { ...@@ -62,23 +62,21 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener {
private var receiver: BroadcastReceiver? = null private var receiver: BroadcastReceiver? = null
private var cachedApps: List<PackageInfo>? = null private var cachedApps: List<PackageInfo>? = null
private fun getApps(pm: PackageManager): List<ProxiedApp> { private fun getApps(pm: PackageManager) = synchronized(AppManager) {
return synchronized(AppManager) { if (receiver == null) receiver = app.listenForPackageChanges {
if (receiver == null) receiver = app.listenForPackageChanges { synchronized(AppManager) {
synchronized(AppManager) { receiver = null
receiver = null cachedApps = null
cachedApps = null
}
AppManager.instance?.reloadApps()
} }
// Labels and icons can change on configuration (locale, etc.) changes, therefore they are not cached. AppManager.instance?.reloadApps()
val cachedApps = cachedApps ?: pm.getInstalledPackages(PackageManager.GET_PERMISSIONS) }
.filter { it.packageName != app.packageName && // Labels and icons can change on configuration (locale, etc.) changes, therefore they are not cached.
it.requestedPermissions?.contains(Manifest.permission.INTERNET) ?: false } val cachedApps = cachedApps ?: pm.getInstalledPackages(PackageManager.GET_PERMISSIONS)
this.cachedApps = cachedApps .filter { it.packageName != app.packageName &&
cachedApps it.requestedPermissions?.contains(Manifest.permission.INTERNET) ?: false }
}.map { ProxiedApp(pm, it.applicationInfo, it.packageName) } this.cachedApps = cachedApps
} cachedApps
}.map { ProxiedApp(pm, it.applicationInfo, it.packageName) }
} }
private class ProxiedApp(private val pm: PackageManager, private val appInfo: ApplicationInfo, private class ProxiedApp(private val pm: PackageManager, private val appInfo: ApplicationInfo,
......
...@@ -117,7 +117,10 @@ object BaseService { ...@@ -117,7 +117,10 @@ object BaseService {
val item = callbacks.getBroadcastItem(i) val item = callbacks.getBroadcastItem(i)
if (bandwidthListeners.contains(item.asBinder())) if (bandwidthListeners.contains(item.asBinder()))
item.trafficUpdated(profile!!.id, txRate, rxRate, txTotal, rxTotal) item.trafficUpdated(profile!!.id, txRate, rxRate, txTotal, rxTotal)
} catch (_: Exception) { } // ignore } catch (e: Exception) {
e.printStackTrace()
app.track(e)
}
callbacks.finishBroadcast() callbacks.finishBroadcast()
} }
} }
...@@ -159,7 +162,10 @@ object BaseService { ...@@ -159,7 +162,10 @@ object BaseService {
try { try {
val item = callbacks.getBroadcastItem(i) val item = callbacks.getBroadcastItem(i)
if (bandwidthListeners.contains(item.asBinder())) item.trafficPersisted(profile.id) if (bandwidthListeners.contains(item.asBinder())) item.trafficPersisted(profile.id)
} catch (_: Exception) { } // ignore } catch (e: Exception) {
e.printStackTrace()
app.track(e)
}
} }
callbacks.finishBroadcast() callbacks.finishBroadcast()
} }
...@@ -211,7 +217,10 @@ object BaseService { ...@@ -211,7 +217,10 @@ object BaseService {
val n = callbacks.beginBroadcast() val n = callbacks.beginBroadcast()
for (i in 0 until n) try { for (i in 0 until n) try {
callbacks.getBroadcastItem(i).stateChanged(s, binder.profileName, msg) callbacks.getBroadcastItem(i).stateChanged(s, binder.profileName, msg)
} catch (_: Exception) { } // ignore } catch (e: Exception) {
e.printStackTrace()
app.track(e)
}
callbacks.finishBroadcast() callbacks.finishBroadcast()
} }
state = s state = s
......
...@@ -87,21 +87,19 @@ object PluginManager { ...@@ -87,21 +87,19 @@ object PluginManager {
private var receiver: BroadcastReceiver? = null private var receiver: BroadcastReceiver? = null
private var cachedPlugins: Map<String, Plugin>? = null private var cachedPlugins: Map<String, Plugin>? = null
fun fetchPlugins(): Map<String, Plugin> { fun fetchPlugins(): Map<String, Plugin> = synchronized(this) {
return synchronized(this) { if (receiver == null) receiver = app.listenForPackageChanges {
if (receiver == null) receiver = app.listenForPackageChanges { synchronized(this) {
synchronized(this) { receiver = null
receiver = null cachedPlugins = null
cachedPlugins = null
}
}
if (cachedPlugins == null) {
val pm = app.packageManager
cachedPlugins = (pm.queryIntentContentProviders(Intent(PluginContract.ACTION_NATIVE_PLUGIN),
PackageManager.GET_META_DATA).map { NativePlugin(it) } + NoPlugin).associate { it.id to it }
} }
cachedPlugins!!
} }
if (cachedPlugins == null) {
val pm = app.packageManager
cachedPlugins = (pm.queryIntentContentProviders(Intent(PluginContract.ACTION_NATIVE_PLUGIN),
PackageManager.GET_META_DATA).map { NativePlugin(it) } + NoPlugin).associate { it.id to it }
}
cachedPlugins!!
} }
private fun buildUri(id: String) = Uri.Builder() private fun buildUri(id: String) = Uri.Builder()
......
...@@ -22,7 +22,6 @@ package com.github.shadowsocks.preference ...@@ -22,7 +22,6 @@ package com.github.shadowsocks.preference
import android.os.Binder import android.os.Binder
import com.github.shadowsocks.App.Companion.app import com.github.shadowsocks.App.Companion.app
import com.github.shadowsocks.BootReceiver
import com.github.shadowsocks.database.PrivateDatabase import com.github.shadowsocks.database.PrivateDatabase
import com.github.shadowsocks.database.PublicDatabase import com.github.shadowsocks.database.PublicDatabase
import com.github.shadowsocks.utils.DirectBoot import com.github.shadowsocks.utils.DirectBoot
......
...@@ -29,8 +29,8 @@ import com.twofortyfouram.locale.api.Intent as ApiIntent ...@@ -29,8 +29,8 @@ import com.twofortyfouram.locale.api.Intent as ApiIntent
class Settings(bundle: Bundle?) { class Settings(bundle: Bundle?) {
companion object { companion object {
private val KEY_SWITCH_ON = "switch_on" private const val KEY_SWITCH_ON = "switch_on"
private val KEY_PROFILE_ID = "profile_id" private const val KEY_PROFILE_ID = "profile_id"
fun fromIntent(intent: Intent) = Settings(intent.getBundleExtra(ApiIntent.EXTRA_BUNDLE)) fun fromIntent(intent: Intent) = Settings(intent.getBundleExtra(ApiIntent.EXTRA_BUNDLE))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment