Improve debug logging mechanisms

This commit is contained in:
Mygod
2018-12-30 15:49:43 +08:00
parent f59ddb5616
commit fe33c88047
16 changed files with 99 additions and 71 deletions

View File

@@ -6,13 +6,19 @@ import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.view.View
import androidx.core.os.bundleOf
import androidx.databinding.BaseObservable
import androidx.recyclerview.widget.RecyclerView
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.databinding.ListitemManageBinding
import timber.log.Timber
object ManageBar : Manager() {
private const val TAG = "ManageBar"
private const val SETTINGS_PACKAGE = "com.android.settings"
private const val SETTINGS_1 = "com.android.settings.Settings\$TetherSettingsActivity"
private const val SETTINGS_2 = "com.android.settings.TetherSettings"
object Data : BaseObservable() {
/**
* It's hard to change tethering rules with Tethering hardware acceleration enabled for now.
@@ -38,8 +44,7 @@ object ManageBar : Manager() {
fun start(context: Context) {
try {
context.startActivity(Intent()
.setClassName("com.android.settings", "com.android.settings.Settings\$TetherSettingsActivity"))
context.startActivity(Intent().setClassName(SETTINGS_PACKAGE, SETTINGS_1))
} catch (e: ActivityNotFoundException) {
startAlternative(context, e)
} catch (e: SecurityException) {
@@ -49,13 +54,12 @@ object ManageBar : Manager() {
private fun startAlternative(context: Context, e: RuntimeException) {
try {
context.startActivity(Intent()
.setClassName("com.android.settings", "com.android.settings.TetherSettings"))
Timber.w(e)
context.startActivity(Intent().setClassName("com.android.settings", SETTINGS_2))
DebugHelper.logEvent(TAG, bundleOf(Pair(SETTINGS_1, e.message)))
} catch (e: ActivityNotFoundException) {
Timber.w(e)
DebugHelper.logEvent(TAG, bundleOf(Pair(SETTINGS_1, e.message), Pair(SETTINGS_2, e.message)))
} catch (e: SecurityException) {
Timber.w(e)
DebugHelper.logEvent(TAG, bundleOf(Pair(SETTINGS_1, e.message), Pair(SETTINGS_2, e.message)))
}
}
}

View File

@@ -54,7 +54,7 @@ class TetheringFragment : Fragment(), ServiceConnection {
ifaceLookup = try {
NetworkInterface.getNetworkInterfaces().asSequence().associateBy { it.name }
} catch (e: SocketException) {
Timber.w(e)
Timber.d(e)
emptyMap()
}
this@TetheringFragment.enabledTypes =