From d131d5d46bcea1c7e03213c6bc39ea3c88529a6c Mon Sep 17 00:00:00 2001 From: dwuku <43770833+dwuku@users.noreply.github.com> Date: Tue, 2 Oct 2018 15:13:12 +0000 Subject: [PATCH] Make compatible with F-Droid (#42) * Make compatible with F-Droid * Fix title bar empty --- mobile/build.gradle | 21 +++++++++++---- .../java/be/mygod/vpnhotspot/EBegFragment.kt | 14 +++++----- .../base/java/be/mygod/vpnhotspot/Timber.kt | 25 +++++++++++++++++ .../java/be/mygod/vpnhotspot/EBegFragment.kt | 27 +++++++++++++++++++ .../fdroid/java/be/mygod/vpnhotspot/Timber.kt | 7 +++++ mobile/src/main/AndroidManifest.xml | 4 ++- .../src/main/java/be/mygod/vpnhotspot/App.kt | 4 +-- .../vpnhotspot/LocalOnlyHotspotService.kt | 23 ++++++++-------- .../vpnhotspot/LocalOnlyInterfaceManager.kt | 4 +-- .../java/be/mygod/vpnhotspot/MainActivity.kt | 9 +++---- .../be/mygod/vpnhotspot/RepeaterService.kt | 25 +++++++---------- .../vpnhotspot/SettingsPreferenceFragment.kt | 15 +++++------ .../be/mygod/vpnhotspot/TetheringService.kt | 5 ++-- .../manage/LocalOnlyHotspotManager.kt | 7 +++-- .../be/mygod/vpnhotspot/manage/ManageBar.kt | 11 +++----- .../vpnhotspot/manage/RepeaterManager.kt | 8 +++--- .../mygod/vpnhotspot/manage/TetherManager.kt | 18 +++++-------- .../vpnhotspot/manage/TetheringFragment.kt | 5 ++-- .../java/be/mygod/vpnhotspot/net/IpMonitor.kt | 22 +++++++-------- .../be/mygod/vpnhotspot/net/IpNeighbour.kt | 12 +++------ .../vpnhotspot/net/IpNeighbourMonitor.kt | 2 +- .../java/be/mygod/vpnhotspot/net/Routing.kt | 7 +++-- .../mygod/vpnhotspot/net/TetheringManager.kt | 9 +++---- .../mygod/vpnhotspot/net/TrafficRecorder.kt | 8 +++--- .../be/mygod/vpnhotspot/net/VpnMonitor.kt | 2 +- .../net/wifi/P2pSupplicantConfiguration.kt | 13 ++++----- .../net/wifi/WifiP2pManagerHelper.kt | 17 +++++------- .../be/mygod/vpnhotspot/util/RootSession.kt | 9 +++---- .../java/be/mygod/vpnhotspot/util/Utils.kt | 12 +++------ mobile/src/main/res/layout/fragment_ebeg.xml | 14 +++++++--- 30 files changed, 193 insertions(+), 166 deletions(-) rename mobile/src/{main => base}/java/be/mygod/vpnhotspot/EBegFragment.kt (91%) create mode 100644 mobile/src/base/java/be/mygod/vpnhotspot/Timber.kt create mode 100644 mobile/src/fdroid/java/be/mygod/vpnhotspot/EBegFragment.kt create mode 100644 mobile/src/fdroid/java/be/mygod/vpnhotspot/Timber.kt diff --git a/mobile/build.gradle b/mobile/build.gradle index b3257caa..cb947ba8 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -1,8 +1,10 @@ apply plugin: 'com.android.application' -apply plugin: 'io.fabric' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +if (getGradle().getStartParameter().getTaskRequests().toString().contains("base")) + apply plugin: 'io.fabric' + android { buildToolsVersion "28.0.3" compileSdkVersion 28 @@ -31,8 +33,15 @@ android { } } dataBinding.enabled = true - flavorDimensions("freedom") + flavorDimensions("fdroid", "freedom") productFlavors { + base { + dimension "fdroid" + } + fdroid { + dimension "fdroid" + } + freedom { dimension "freedom" buildConfigField "boolean", "DONATIONS", "true" @@ -52,18 +61,20 @@ dependencies { implementation "androidx.core:core-ktx:$androidxVersion" implementation "androidx.preference:preference:$androidxVersion" implementation "androidx.room:room-runtime:$roomVersion" - implementation 'com.android.billingclient:billing:1.1' - implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.github.luongvo:BadgeView:1.1.5' implementation 'com.github.topjohnwu:libsu:2.0.2' implementation "com.google.android.material:material:$androidxVersion" + implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.linkedin.dexmaker:dexmaker-mockito:2.19.1' implementation 'com.takisoft.preferencex:preferencex:1.0.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" + baseImplementation 'com.android.billingclient:billing:1.1' + baseImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' testImplementation "androidx.room:room-testing:$roomVersion" testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' } -apply plugin: 'com.google.gms.google-services' +if (getGradle().getStartParameter().getTaskRequests().toString().contains("base")) + apply plugin: 'com.google.gms.google-services' diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/EBegFragment.kt b/mobile/src/base/java/be/mygod/vpnhotspot/EBegFragment.kt similarity index 91% rename from mobile/src/main/java/be/mygod/vpnhotspot/EBegFragment.kt rename to mobile/src/base/java/be/mygod/vpnhotspot/EBegFragment.kt index 6f590176..952b3ae0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/EBegFragment.kt +++ b/mobile/src/base/java/be/mygod/vpnhotspot/EBegFragment.kt @@ -1,7 +1,6 @@ package be.mygod.vpnhotspot import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -15,7 +14,7 @@ import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import com.android.billingclient.api.* -import com.crashlytics.android.Crashlytics +import timber.log.Timber /** * Based on: https://github.com/PrivacyApps/donations/blob/747d36a18433c7e9329691054122a8ad337a62d2/Donations/src/main/java/org/sufficientlysecure/donations/DonationsFragment.java @@ -23,7 +22,6 @@ import com.crashlytics.android.Crashlytics class EBegFragment : DialogFragment(), PurchasesUpdatedListener, BillingClientStateListener, SkuDetailsResponseListener, ConsumeResponseListener { companion object { - private const val TAG = "EBegFragment" private const val KEY_TITLE = "title" private const val KEY_MESSAGE = "message" } @@ -80,6 +78,7 @@ class EBegFragment : DialogFragment(), PurchasesUpdatedListener, BillingClientSt billingClient = BillingClient.newBuilder(context ?: return).setListener(this).build() .also { it.startConnection(this) } } + override fun onBillingSetupFinished(responseCode: Int) { if (responseCode == BillingClient.BillingResponse.OK) { billingClient.querySkuDetailsAsync( @@ -88,24 +87,25 @@ class EBegFragment : DialogFragment(), PurchasesUpdatedListener, BillingClientSt "donate100", "donate200", "donatemax")) setType(BillingClient.SkuType.INAPP) }.build(), this) - } else Crashlytics.log(Log.ERROR, TAG, "onBillingSetupFinished: $responseCode") + } else Timber.e("onBillingSetupFinished: $responseCode") } override fun onSkuDetailsResponse(responseCode: Int, skuDetailsList: MutableList?) { if (responseCode == BillingClient.BillingResponse.OK) skus = skuDetailsList - else Crashlytics.log(Log.ERROR, TAG, "onSkuDetailsResponse: $responseCode") + else Timber.e("onSkuDetailsResponse: $responseCode") } override fun onPurchasesUpdated(responseCode: Int, purchases: MutableList?) { if (responseCode == BillingClient.BillingResponse.OK && purchases != null) { // directly consume in-app purchase, so that people can donate multiple times purchases.forEach { billingClient.consumeAsync(it.purchaseToken, this) } - } else Crashlytics.log(Log.ERROR, TAG, "onPurchasesUpdated: $responseCode") + } else Timber.e("onPurchasesUpdated: $responseCode") } + override fun onConsumeResponse(responseCode: Int, purchaseToken: String?) { if (responseCode == BillingClient.BillingResponse.OK) { openDialog(R.string.donations__thanks_dialog_title, R.string.donations__thanks_dialog) dismissAllowingStateLoss() - } else Crashlytics.log(Log.ERROR, TAG, "onConsumeResponse: $responseCode") + } else Timber.e("onConsumeResponse: $responseCode") } } diff --git a/mobile/src/base/java/be/mygod/vpnhotspot/Timber.kt b/mobile/src/base/java/be/mygod/vpnhotspot/Timber.kt new file mode 100644 index 00000000..1a7d1b9b --- /dev/null +++ b/mobile/src/base/java/be/mygod/vpnhotspot/Timber.kt @@ -0,0 +1,25 @@ +package be.mygod.vpnhotspot + +import android.util.Log +import be.mygod.vpnhotspot.App.Companion.app +import com.crashlytics.android.Crashlytics +import io.fabric.sdk.android.Fabric +import timber.log.Timber + +fun initTimber() { + Fabric.with(app, Crashlytics()) + Timber.plant(object : Timber.Tree() { + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { + if (t == null) Crashlytics.log(priority, tag, message) else { + // Crashlytics.logException doesn't print to logcat + if (priority >= Log.WARN || priority == Log.DEBUG) Log.println(priority, tag, message) + if (priority >= Log.INFO) Crashlytics.logException(t) + } + } + }) +} + +fun debugLog(tag: String?, message: String?) { + if (BuildConfig.DEBUG) Timber.d(tag, message) + Crashlytics.log("$tag: $message") +} diff --git a/mobile/src/fdroid/java/be/mygod/vpnhotspot/EBegFragment.kt b/mobile/src/fdroid/java/be/mygod/vpnhotspot/EBegFragment.kt new file mode 100644 index 00000000..f71e5050 --- /dev/null +++ b/mobile/src/fdroid/java/be/mygod/vpnhotspot/EBegFragment.kt @@ -0,0 +1,27 @@ +package be.mygod.vpnhotspot + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.ViewStub +import android.widget.Button +import android.widget.LinearLayout +import androidx.core.net.toUri +import androidx.fragment.app.DialogFragment + +/** + * Based on: https://github.com/PrivacyApps/donations/blob/747d36a18433c7e9329691054122a8ad337a62d2/Donations/src/main/java/org/sufficientlysecure/donations/DonationsFragment.java + */ +class EBegFragment : DialogFragment() { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + inflater.inflate(R.layout.fragment_ebeg, container, false) + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + view.findViewById(R.id.donations__google).visibility = View.GONE + (view.findViewById(R.id.donations__more_stub).inflate() as Button).setOnClickListener { + (activity as MainActivity).launchUrl("https://mygod.be/donate/".toUri()) + } + } +} diff --git a/mobile/src/fdroid/java/be/mygod/vpnhotspot/Timber.kt b/mobile/src/fdroid/java/be/mygod/vpnhotspot/Timber.kt new file mode 100644 index 00000000..d7048639 --- /dev/null +++ b/mobile/src/fdroid/java/be/mygod/vpnhotspot/Timber.kt @@ -0,0 +1,7 @@ +package be.mygod.vpnhotspot + +import timber.log.Timber + +fun initTimber() = Timber.plant(Timber.DebugTree()) + +fun debugLog(tag: String?, message: String?) = Timber.d(tag, message) diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index 2b76cd14..d708600d 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -45,7 +45,9 @@ android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + tools:ignore="GoogleAppIndexingWarning"> + diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt index e497b4d6..5096b3dc 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/App.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/App.kt @@ -14,8 +14,6 @@ import be.mygod.vpnhotspot.room.AppDatabase import be.mygod.vpnhotspot.util.DeviceStorageApp import be.mygod.vpnhotspot.util.Event0 import be.mygod.vpnhotspot.util.RootSession -import com.crashlytics.android.Crashlytics -import io.fabric.sdk.android.Fabric class App : Application() { companion object { @@ -33,7 +31,7 @@ class App : Application() { deviceStorage.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(this)) deviceStorage.moveDatabaseFrom(this, AppDatabase.DB_NAME) } else deviceStorage = this - Fabric.with(deviceStorage, Crashlytics()) + initTimber() ServiceNotification.updateNotificationChannels() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 13afdab6..8c072492 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -9,9 +9,8 @@ import be.mygod.vpnhotspot.manage.LocalOnlyHotspotManager import be.mygod.vpnhotspot.net.IpNeighbourMonitor import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.util.broadcastReceiver -import be.mygod.vpnhotspot.util.debugLog import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber @RequiresApi(26) class LocalOnlyHotspotService : IpNeighbourMonitoringService() { @@ -90,23 +89,23 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() { else -> getString(R.string.failure_reason_unknown, reason) }) SmartSnackbar.make(message).show() - startFailure(if (reason == WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE) null else - StartFailure(message)) + if (reason != WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE) { + Timber.i(StartFailure(message)) + } + startFailure() } }, app.handler) - } catch (e: IllegalStateException) { - e.printStackTrace() - startFailure(e) - } catch (e: SecurityException) { + // assuming IllegalStateException will be thrown only if + // "Caller already has an active LocalOnlyHotspot request" + } catch (_: IllegalStateException) { } catch (e: SecurityException) { SmartSnackbar.make(e.localizedMessage).show() - e.printStackTrace() - startFailure(e) + Timber.w(e) + startFailure() } return START_STICKY } - private fun startFailure(e: Exception?) { - if (e?.message != "Caller already has an active LocalOnlyHotspot request") Crashlytics.logException(e) + private fun startFailure() { updateNotification() ServiceNotification.stopForeground(this@LocalOnlyHotspotService) stopSelf() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt index f7aa41b3..d97e1f1c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyInterfaceManager.kt @@ -5,7 +5,7 @@ import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.Routing import be.mygod.vpnhotspot.net.UpstreamMonitor import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.InetAddress import java.net.InterfaceAddress @@ -57,7 +57,7 @@ class LocalOnlyInterfaceManager(private val owner: Context, val downstream: Stri } } catch (e: Exception) { SmartSnackbar.make(e.localizedMessage).show() - Crashlytics.logException(e) + Timber.w(e) routing = null } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt b/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt index 03d4ffc9..d640d741 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt @@ -20,10 +20,10 @@ import be.mygod.vpnhotspot.databinding.ActivityMainBinding import be.mygod.vpnhotspot.manage.TetheringFragment import be.mygod.vpnhotspot.util.ServiceForegroundConnector import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics import com.google.android.material.bottomnavigation.BottomNavigationMenuView import com.google.android.material.bottomnavigation.BottomNavigationView import q.rorbin.badgeview.QBadgeView +import timber.log.Timber class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener, ServiceConnection { companion object { @@ -38,15 +38,14 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS .setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)) .build() } + fun launchUrl(url: Uri) = try { customTabsIntent.launchUrl(this, url) } catch (e: ActivityNotFoundException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) SmartSnackbar.make(url.toString()).show() } catch (e: SecurityException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) SmartSnackbar.make(url.toString()).show() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index aecf7311..883514ab 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -22,7 +22,7 @@ import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.setWifiP2pChannels import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.startWps import be.mygod.vpnhotspot.util.* import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.lang.reflect.InvocationTargetException class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPreferences.OnSharedPreferenceChangeListener { @@ -33,7 +33,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere enum class Status { IDLE, STARTING, ACTIVE } - private class Failure(message: String) : RuntimeException(message) + private class Failure(message: String, cause: Throwable? = null) : RuntimeException(message, cause) inner class Binder : android.os.Binder() { val service get() = this@RepeaterService @@ -79,8 +79,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere if (it.size == 1) group = it.single() } } catch (e: ReflectiveOperationException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) SmartSnackbar.make(e.localizedMessage).show() } } @@ -124,7 +123,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere WifiP2pManagerHelper.UNSUPPORTED -> getString(R.string.repeater_failure_reason_unsupported_operation) else -> getString(R.string.failure_reason_unknown, reason) }) - Crashlytics.logException(Failure(result)) + Timber.i(Failure(result)) return result } @@ -134,9 +133,8 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere p2pManager = getSystemService()!! onChannelDisconnected() app.pref.registerOnSharedPreferenceChangeListener(this) - } catch (exc: RuntimeException) { - exc.printStackTrace() - Crashlytics.logException(exc) + } catch (e: RuntimeException) { + Timber.w(e) } } @@ -154,10 +152,8 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere if (oc != 0) { val message = getString(R.string.repeater_set_oc_failure, e.message) SmartSnackbar.make(message).show() - Crashlytics.logException(Failure(message)) - } - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(Failure(message, e)) + } else Timber.w(e) } override fun onChannelDisconnected() { @@ -179,8 +175,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere val out = try { RootSession.use { it.execOut("dumpsys ${Context.WIFI_P2P_SERVICE}") } } catch (e: RuntimeException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) startFailure(e.localizedMessage) return START_NOT_STICKY } @@ -197,7 +192,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere it == null -> doStart() it.isGroupOwner -> if (routingManager == null) doStart(it) else -> { - Crashlytics.log(Log.INFO, TAG, "Removing old group ($it)") + Timber.i("Removing old group ($it)") p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener { override fun onSuccess() = doStart() override fun onFailure(reason: Int) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt index 753c9408..3f1d1443 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt @@ -7,6 +7,7 @@ import android.os.Bundle import androidx.core.content.FileProvider import androidx.core.net.toUri import androidx.core.os.bundleOf +import androidx.fragment.app.DialogFragment import androidx.preference.Preference import androidx.preference.SwitchPreference import be.mygod.vpnhotspot.App.Companion.app @@ -16,8 +17,8 @@ import be.mygod.vpnhotspot.preference.AlwaysAutoCompleteEditTextPreferenceDialog import be.mygod.vpnhotspot.preference.SharedPreferenceDataStore import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics import com.takisoft.preferencex.PreferenceFragmentCompat +import timber.log.Timber import java.io.File import java.io.IOException import java.io.PrintWriter @@ -39,7 +40,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() { Routing.clean() true } catch (e: RuntimeException) { - e.printStackTrace() + Timber.d(e) SmartSnackbar.make(e.localizedMessage).show() false } @@ -58,8 +59,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() { try { Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.use { it.copyTo(out) } } catch (e: IOException) { - e.printStackTrace(writer) - Crashlytics.logException(e) + Timber.w(e) } writer.write("\n") writer.flush() @@ -93,8 +93,8 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() { .joinToString("\n").toByteArray()) } catch (e: Exception) { e.printStackTrace(writer) - Crashlytics.logException(e) writer.flush() + Timber.i(e) } } } @@ -111,7 +111,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() { true } findPreference("misc.donate").setOnPreferenceClickListener { - EBegFragment().show(fragmentManager, "ebeg_fragment") + EBegFragment().apply { setStyle(DialogFragment.STYLE_NO_TITLE, 0) }.show(fragmentManager, "EBegFragment") true } } @@ -125,8 +125,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() { .filter { it.isUp && !it.isLoopback && it.interfaceAddresses.isNotEmpty() } .map { it.name }.sorted().toList().toTypedArray() } catch (e: SocketException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) emptyArray() }))) else -> super.onDisplayPreferenceDialog(preference) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index 09eb7ebf..f7dc0677 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -10,7 +10,7 @@ import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.UpstreamMonitor import be.mygod.vpnhotspot.util.broadcastReceiver import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.InetAddress class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callback { @@ -84,8 +84,7 @@ class TetheringService : IpNeighbourMonitoringService(), UpstreamMonitor.Callbac } } } catch (e: Exception) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) SmartSnackbar.make(e.localizedMessage).show() iterator.remove() } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt index fdf1ee9b..ff6f4021 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt @@ -25,7 +25,7 @@ import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding import be.mygod.vpnhotspot.net.TetherType import be.mygod.vpnhotspot.util.ServiceForegroundConnector import be.mygod.vpnhotspot.util.formatAddresses -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.NetworkInterface @TargetApi(26) @@ -60,9 +60,8 @@ class LocalOnlyHotspotManager(private val parent: TetheringFragment) : Manager() Toast.makeText(view.context, R.string.tethering_temp_hotspot_location, Toast.LENGTH_LONG).show() try { view.context.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) - } catch (exc: ActivityNotFoundException) { - exc.printStackTrace() - Crashlytics.logException(exc) + } catch (e: ActivityNotFoundException) { + Timber.w(e) } return } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt index 9aa39183..3c748d1b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt @@ -10,7 +10,7 @@ import androidx.databinding.BaseObservable import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.databinding.ListitemManageBinding -import com.crashlytics.android.Crashlytics +import timber.log.Timber object ManageBar : Manager() { object Data : BaseObservable() { @@ -51,14 +51,11 @@ object ManageBar : Manager() { try { context.startActivity(Intent() .setClassName("com.android.settings", "com.android.settings.TetherSettings")) - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) } catch (e: ActivityNotFoundException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) } catch (e: SecurityException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) } } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt index 992dddb2..53f9550e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt @@ -24,7 +24,7 @@ import be.mygod.vpnhotspot.net.wifi.WifiP2pDialogFragment import be.mygod.vpnhotspot.util.ServiceForegroundConnector import be.mygod.vpnhotspot.util.formatAddresses import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.NetworkInterface import java.net.SocketException @@ -47,8 +47,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic return try { NetworkInterface.getByName(p2pInterface ?: return "")?.formatAddresses() ?: "" } catch (e: SocketException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) "" } } @@ -174,8 +173,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic .update(data.getParcelableExtra(WifiP2pDialogFragment.KEY_CONFIGURATION)) app.handler.postDelayed(binder!!::requestGroupUpdate, 1000) } catch (e: RuntimeException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) SmartSnackbar.make(e.localizedMessage).show() } DialogInterface.BUTTON_NEUTRAL -> binder!!.resetCredentials() 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 5513e88c..1750900a 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -24,7 +24,7 @@ import be.mygod.vpnhotspot.net.TetherType import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.wifi.WifiApManager import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.io.IOException import java.lang.reflect.InvocationTargetException @@ -51,21 +51,18 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), manager.parent.startActivity(Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, "package:${mainActivity.packageName}".toUri())) return - } catch (exc: ActivityNotFoundException) { - exc.printStackTrace() - Crashlytics.logException(exc) + } catch (e: ActivityNotFoundException) { + Timber.w(e) } val started = manager.isStarted try { if (started) manager.stop() else manager.start() } catch (e: IOException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) Toast.makeText(mainActivity, e.localizedMessage, Toast.LENGTH_LONG).show() ManageBar.start(itemView.context) } catch (e: InvocationTargetException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) var cause: Throwable? = e while (cause != null) { cause = cause.cause @@ -125,7 +122,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), else -> app.getString(R.string.failure_reason_unknown, error) } } catch (e: InvocationTargetException) { - Crashlytics.logException(e) + Timber.w(e) e.localizedMessage } } @@ -171,8 +168,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), try { BluetoothAdapter.getDefaultAdapter()?.getProfileProxy(parent.requireContext(), this, PAN) } catch (e: SecurityException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) SmartSnackbar.make(e.localizedMessage).show() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt index 2f0e00cd..8152d50a 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -26,7 +26,7 @@ import be.mygod.vpnhotspot.net.TetherType import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.util.ServiceForegroundConnector import be.mygod.vpnhotspot.util.broadcastReceiver -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.NetworkInterface import java.net.SocketException @@ -53,8 +53,7 @@ class TetheringFragment : Fragment(), ServiceConnection { ifaceLookup = try { NetworkInterface.getNetworkInterfaces().asSequence().associateBy { it.name } } catch (e: SocketException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) emptyMap() } this@TetheringFragment.enabledTypes = diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt index eff7ef25..e721892e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt @@ -4,7 +4,7 @@ import android.util.Log import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.util.thread import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.io.IOException import java.io.InterruptedIOException import java.util.concurrent.Executors @@ -25,25 +25,21 @@ abstract class IpMonitor : Runnable { val process = try { builder.start() } catch (e: IOException) { - e.printStackTrace() + Timber.d(e) return false } monitor = process val err = thread("${javaClass.simpleName}-error") { try { - process.errorStream.bufferedReader().forEachLine { - Crashlytics.log(Log.ERROR, javaClass.simpleName, it) - } + process.errorStream.bufferedReader().forEachLine { Timber.e(it) } } catch (_: InterruptedIOException) { } catch (e: IOException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) } } try { process.inputStream.bufferedReader().forEachLine(this::processLine) } catch (_: InterruptedIOException) { } catch (e: IOException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) } err.join() process.waitFor() @@ -56,8 +52,8 @@ abstract class IpMonitor : Runnable { // monitor may get rejected by SELinux if (handleProcess(ProcessBuilder("ip", "monitor", monitoredObject))) return@thread if (handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject"))) return@thread - Crashlytics.log(Log.WARN, javaClass.simpleName, "Failed to set up monitor, switching to polling") - Crashlytics.logException(MonitorFailure()) + Timber.w("Failed to set up monitor, switching to polling") + Timber.i(MonitorFailure()) val pool = Executors.newScheduledThreadPool(1) pool.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS) this.pool = pool @@ -74,8 +70,8 @@ abstract class IpMonitor : Runnable { thread("${javaClass.simpleName}-flush-error") { val err = process.errorStream.bufferedReader().readText() if (err.isNotBlank()) { - Crashlytics.log(Log.ERROR, javaClass.simpleName, err) - Crashlytics.logException(FlushFailure()) + Timber.e(err) + Timber.i(FlushFailure()) SmartSnackbar.make(R.string.noisy_su_failure).show() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt index f6cd0421..57877e3d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbour.kt @@ -1,8 +1,7 @@ package be.mygod.vpnhotspot.net -import android.util.Log import be.mygod.vpnhotspot.util.parseNumericAddressNoThrow -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.io.File import java.io.IOException import java.net.InetAddress @@ -13,8 +12,6 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String, } companion object { - private const val TAG = "IpNeighbour" - /** * Parser based on: * https://android.googlesource.com/platform/external/iproute2/+/ad0a6a2/ip/ipneigh.c#194 @@ -28,7 +25,7 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String, fun parse(line: String): IpNeighbour? { val match = parser.matchEntire(line) if (match == null) { - if (line.isNotEmpty()) Crashlytics.log(Log.WARN, TAG, line) + if (line.isNotEmpty()) Timber.w(line) return null } val ip = parseNumericAddressNoThrow(match.groupValues[2]) ?: return null @@ -47,7 +44,7 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String, "FAILED" -> State.FAILED "NOARP" -> return null // skip else -> { - Crashlytics.log(Log.WARN, TAG, "Unknown state encountered: ${match.groupValues[10]}") + Timber.w("Unknown state encountered: ${match.groupValues[10]}") return null } } @@ -73,8 +70,7 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String, .filter { it.size >= 6 && mac.matcher(it[ARP_HW_ADDRESS]).matches() } .toList() } catch (e: IOException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) } return arpCache } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbourMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbourMonitor.kt index db0e2fa6..37ecbede 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbourMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpNeighbourMonitor.kt @@ -1,7 +1,7 @@ package be.mygod.vpnhotspot.net import be.mygod.vpnhotspot.App.Companion.app -import be.mygod.vpnhotspot.util.debugLog +import be.mygod.vpnhotspot.debugLog import java.net.InetAddress class IpNeighbourMonitor private constructor() : IpMonitor() { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index 3a964910..b967897d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -10,12 +10,12 @@ import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.client.Client import be.mygod.vpnhotspot.client.ClientMonitorService +import be.mygod.vpnhotspot.debugLog import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.util.computeIfAbsentCompat -import be.mygod.vpnhotspot.util.debugLog import be.mygod.vpnhotspot.util.stopAndUnbind import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.* /** @@ -165,8 +165,7 @@ class Routing(private val owner: Context, val upstream: String?, private val dow try { subroutes.computeIfAbsentCompat(ip) { Subroute(ip, client) } } catch (e: Exception) { - Crashlytics.logException(e) - e.printStackTrace() + Timber.w(e) SmartSnackbar.make(e.localizedMessage).show() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt index 0662bf84..71af2a06 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -5,11 +5,10 @@ import android.net.ConnectivityManager import android.os.Build import android.os.Bundle import android.os.Handler -import android.util.Log import androidx.annotation.RequiresApi import be.mygod.vpnhotspot.App.Companion.app import com.android.dx.stock.ProxyBuilder -import com.crashlytics.android.Crashlytics +import timber.log.Timber /** * Heavily based on: @@ -32,8 +31,6 @@ object TetheringManager { fun onTetheringFailed() { } } - private const val TAG = "TetheringManager" - /** * This is a sticky broadcast since almost forever. * @@ -121,7 +118,7 @@ object TetheringManager { val proxy = ProxyBuilder.forClass(classOnStartTetheringCallback) .dexCache(app.cacheDir) .handler { proxy, method, args -> - if (args.isNotEmpty()) Crashlytics.log(Log.WARN, TAG, "Unexpected args for ${method.name}: $args") + if (args.isNotEmpty()) Timber.w("Unexpected args for ${method.name}: $args") when (method.name) { "onTetheringStarted" -> { callback.onTetheringStarted() @@ -132,7 +129,7 @@ object TetheringManager { null } else -> { - Crashlytics.log(Log.WARN, TAG, "Unexpected method, calling super: $method") + Timber.w("Unexpected method, calling super: $method") ProxyBuilder.callSuper(proxy, method, args) } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TrafficRecorder.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TrafficRecorder.kt index 16e52a72..27c6f5ca 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TrafficRecorder.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TrafficRecorder.kt @@ -1,7 +1,6 @@ package be.mygod.vpnhotspot.net import android.os.SystemClock -import android.util.Log import android.util.LongSparseArray import be.mygod.vpnhotspot.room.AppDatabase import be.mygod.vpnhotspot.room.TrafficRecord @@ -10,7 +9,7 @@ import be.mygod.vpnhotspot.room.macToLong import be.mygod.vpnhotspot.util.Event2 import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.util.parseNumericAddress -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.InetAddress import java.util.concurrent.TimeUnit @@ -112,9 +111,8 @@ object TrafficRecorder { else -> check(false) } } catch (e: RuntimeException) { - Crashlytics.log(Log.WARN, TAG, line) - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(line) + Timber.w(e) } } for ((_, record) in records) if (record.id == null) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt index bc282b3e..adbbc934 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/VpnMonitor.kt @@ -5,7 +5,7 @@ import android.net.Network import android.net.NetworkCapabilities import android.net.NetworkRequest import be.mygod.vpnhotspot.App.Companion.app -import be.mygod.vpnhotspot.util.debugLog +import be.mygod.vpnhotspot.debugLog object VpnMonitor : UpstreamMonitor() { private const val TAG = "VpnMonitor" diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt index c8e6b01a..0fa1d8c3 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt @@ -4,10 +4,9 @@ import android.net.wifi.WifiConfiguration import android.os.Build import android.os.Parcel import android.os.Parcelable -import android.util.Log import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.util.RootSession -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.io.File import java.io.IOException @@ -16,7 +15,6 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc override fun createFromParcel(parcel: Parcel) = P2pSupplicantConfiguration(parcel.readString()) override fun newArray(size: Int): Array = arrayOfNulls(size) - private const val TAG = "P2pSupplicationConf" /** * Format for ssid is much more complicated, therefore we are only trying to find the line and rely on * Android's results instead. @@ -55,9 +53,8 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc } catch (e: NoSuchElementException) { null } catch (e: RuntimeException) { - if (contentDelegate.isInitialized()) Crashlytics.log(Log.WARN, TAG, content) - e.printStackTrace() - Crashlytics.logException(e) + if (contentDelegate.isInitialized()) Timber.w(content) + Timber.w(e) null } } @@ -82,9 +79,9 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc }) } if (ssidFound != 1 || pskFound != 1) { - Crashlytics.log(Log.WARN, TAG, "Invalid conf ($ssidFound, $pskFound): $content") + Timber.w("Invalid conf ($ssidFound, $pskFound): $content") if (ssidFound == 0 || pskFound == 0) throw InvalidConfigurationError() - else Crashlytics.logException(InvalidConfigurationError()) + else Timber.i(InvalidConfigurationError()) } // pkill not available on Lollipop. Source: https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md RootSession.use { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt index c3f07e25..1b84b56d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt @@ -4,14 +4,12 @@ import android.annotation.SuppressLint import android.net.wifi.WpsInfo import android.net.wifi.p2p.WifiP2pGroup import android.net.wifi.p2p.WifiP2pManager -import android.util.Log import com.android.dx.stock.ProxyBuilder -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.lang.reflect.Proxy import java.util.regex.Pattern object WifiP2pManagerHelper { - private const val TAG = "WifiP2pManagerHelper" const val UNSUPPORTED = -2 /** @@ -41,8 +39,7 @@ object WifiP2pManagerHelper { try { setWifiP2pChannels.invoke(this, c, lc, oc, listener) } catch (e: NoSuchMethodException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) listener.onFailure(UNSUPPORTED) } } @@ -60,8 +57,7 @@ object WifiP2pManagerHelper { try { startWps.invoke(this, c, wps, listener) } catch (e: NoSuchMethodException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) listener.onFailure(UNSUPPORTED) } } @@ -80,8 +76,7 @@ object WifiP2pManagerHelper { try { deletePersistentGroup.invoke(this, c, netId, listener) } catch (e: NoSuchMethodException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) listener.onFailure(UNSUPPORTED) } } @@ -107,11 +102,11 @@ object WifiP2pManagerHelper { val proxy = Proxy.newProxyInstance(interfacePersistentGroupInfoListener.classLoader, arrayOf(interfacePersistentGroupInfoListener)) { proxy, method, args -> if (method.name == "onPersistentGroupInfoAvailable") { - if (args.size != 1) Crashlytics.log(Log.WARN, TAG, "Unexpected args: $args") + if (args.size != 1) Timber.w("Unexpected args: $args") listener(getGroupList.invoke(args[0]) as Collection) null } else { - Crashlytics.log(Log.WARN, TAG, "Unexpected method, calling super: $method") + Timber.w("Unexpected method, calling super: $method") ProxyBuilder.callSuper(proxy, method, args) } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt index a2cdf2c6..8e1c00c5 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/RootSession.kt @@ -2,10 +2,9 @@ package be.mygod.vpnhotspot.util import android.os.Handler import android.os.HandlerThread -import android.util.Log import androidx.core.os.postDelayed -import com.crashlytics.android.Crashlytics import com.topjohnwu.superuser.Shell +import timber.log.Timber import java.util.* import java.util.concurrent.TimeUnit import java.util.concurrent.locks.ReentrantLock @@ -86,11 +85,11 @@ class RootSession : AutoCloseable { */ fun submit(command: String) { val result = execQuiet(command) - if (result.code != 0) Crashlytics.log(Log.VERBOSE, TAG, "$command exited with ${result.code}") + if (result.code != 0) Timber.v("$command exited with ${result.code}") var msg = result.err.joinToString("\n").trim() - if (msg.isNotEmpty()) Crashlytics.log(Log.VERBOSE, TAG, msg) + if (msg.isNotEmpty()) Timber.v(msg) msg = result.out.joinToString("\n").trim() - if (msg.isNotEmpty()) Crashlytics.log(Log.VERBOSE, TAG, msg) + if (msg.isNotEmpty()) Timber.v(msg) } fun execQuiet(command: String, redirect: Boolean = false): Shell.Result { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt index c8475560..b69b22a9 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt @@ -11,7 +11,7 @@ import androidx.databinding.BindingAdapter import be.mygod.vpnhotspot.BuildConfig import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.widget.SmartSnackbar -import com.crashlytics.android.Crashlytics +import timber.log.Timber import java.net.InetAddress import java.net.NetworkInterface import java.net.SocketException @@ -28,11 +28,6 @@ fun Long.toPluralInt(): Int { fun CharSequence?.onEmpty(otherwise: CharSequence): CharSequence = if (isNullOrEmpty()) otherwise else this!! -fun debugLog(tag: String?, message: String?) { - if (BuildConfig.DEBUG) Log.d(tag, message) - Crashlytics.log("$tag: $message") -} - fun broadcastReceiver(receiver: (Context, Intent) -> Unit) = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) = receiver(context, intent) } @@ -58,8 +53,7 @@ fun NetworkInterface.formatAddresses() = listOfNotNull(try { hardwareAddress?.joinToString(":") { "%02x".format(it) } } catch (e: SocketException) { - e.printStackTrace() - Crashlytics.logException(e) + Timber.w(e) null })) .joinToString("\n") @@ -85,7 +79,7 @@ fun thread(name: String? = null, start: Boolean = true, isDaemon: Boolean = fals val thread = kotlin.concurrent.thread(false, isDaemon, contextClassLoader, name, priority, block) thread.setUncaughtExceptionHandler { _, e -> SmartSnackbar.make(R.string.noisy_su_failure).show() - Crashlytics.logException(e) + Timber.w(e) } if (start) thread.start() return thread diff --git a/mobile/src/main/res/layout/fragment_ebeg.xml b/mobile/src/main/res/layout/fragment_ebeg.xml index c607f8a5..6aa1daef 100644 --- a/mobile/src/main/res/layout/fragment_ebeg.xml +++ b/mobile/src/main/res/layout/fragment_ebeg.xml @@ -7,21 +7,25 @@ + + - + + + +