Browse Source

74: Update logging to gather more information

deploy-in-docker
Ryan Harg 3 years ago committed by Ryan Harg
parent
commit
fe4a00ae07
  1. 29
      app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt
  2. 2
      app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt
  3. 6
      app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt
  4. 11
      app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt
  5. 23
      app/src/main/java/audio/funkwhale/ffa/utils/Util.kt

29
app/src/main/java/audio/funkwhale/ffa/activities/LoginActivity.kt

@ -43,23 +43,20 @@ class LoginActivity : AppCompatActivity() {
data?.let { data?.let {
when (requestCode) { when (requestCode) {
0 -> { 0 -> {
oAuth.exchange(this, data, oAuth.exchange(this, data) {
{ PowerPreference
PowerPreference .getFileByName(AppContext.PREFS_CREDENTIALS)
.getFileByName(AppContext.PREFS_CREDENTIALS) .setBoolean("anonymous", false)
.setBoolean("anonymous", false)
lifecycleScope.launch(Main) {
lifecycleScope.launch(Main) { Userinfo.get(this@LoginActivity, oAuth)?.let {
Userinfo.get(this@LoginActivity, oAuth)?.let { startActivity(Intent(this@LoginActivity, MainActivity::class.java))
startActivity(Intent(this@LoginActivity, MainActivity::class.java))
return@launch finish()
return@launch finish()
}
throw Exception(getString(R.string.login_error_userinfo))
} }
}, throw Exception(getString(R.string.login_error_userinfo))
{ "error".log() } }
) }
} }
} }
} }

2
app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt

@ -637,7 +637,7 @@ class MainActivity : AppCompatActivity() {
.body(Gson().toJson(mapOf("track" to track.id))) .body(Gson().toJson(mapOf("track" to track.id)))
.awaitStringResponse() .awaitStringResponse()
} catch (e: Exception) { } catch (e: Exception) {
e.log() e.logError("incrementListenCount()")
} }
} }
} }

6
app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt

@ -12,6 +12,7 @@ import android.media.MediaMetadata
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.support.v4.media.MediaMetadataCompat import android.support.v4.media.MediaMetadataCompat
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.media.session.MediaButtonReceiver import androidx.media.session.MediaButtonReceiver
@ -479,7 +480,10 @@ class PlayerService : Service() {
super.onPositionDiscontinuity(reason) super.onPositionDiscontinuity(reason)
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) { if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
EventBus.send(Event.TrackFinished(queue.current())) val currentTrack = queue.current().also {
it.log("Track finished")
}
EventBus.send(Event.TrackFinished(currentTrack))
} }
} }

11
app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt

@ -60,7 +60,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
} else { } else {
false false
}.also { }.also {
it.log("isAuthorized()") it.logInfo("isAuthorized()")
} }
} }
@ -75,7 +75,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
state: AuthState, state: AuthState,
context: Context context: Context
): Boolean { ): Boolean {
if (state.needsTokenRefresh.also { it.log("needsTokenRefresh()") } && if (state.needsTokenRefresh.also { it.logInfo("needsTokenRefresh()") } &&
state.refreshToken != null) { state.refreshToken != null) {
val refreshRequest = state.createTokenRefreshRequest() val refreshRequest = state.createTokenRefreshRequest()
val auth = ClientSecretPost(state.clientSecret) val auth = ClientSecretPost(state.clientSecret)
@ -91,7 +91,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
} }
return (state.isAuthorized) return (state.isAuthorized)
.also { .also {
it.log("tryRefreshAccessToken()") it.logInfo("tryRefreshAccessToken()")
} }
} }
@ -171,8 +171,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
fun exchange( fun exchange(
context: Context, context: Context,
authorization: Intent, authorization: Intent,
success: () -> Unit, success: () -> Unit
error: () -> Unit
) { ) {
state().let { state -> state().let { state ->
state.apply { state.apply {
@ -194,7 +193,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
} }
if (response != null) success() if (response != null) success()
else error() else Log.e("FFA", "performTokenRequest() not successful")
} }
} }
} }

23
app/src/main/java/audio/funkwhale/ffa/utils/Util.kt

@ -3,6 +3,8 @@ package audio.funkwhale.ffa.utils
import android.content.Context import android.content.Context
import android.widget.Toast import android.widget.Toast
import com.google.android.exoplayer2.util.Log import com.google.android.exoplayer2.util.Log
import com.google.android.exoplayer2.util.Log.LOG_LEVEL_ERROR
import com.google.android.exoplayer2.util.Log.LOG_LEVEL_INFO
import com.preference.PowerPreference import com.preference.PowerPreference
import java.net.URI import java.net.URI
@ -31,10 +33,23 @@ private fun logClassName(): String {
return "UNKNOWN" return "UNKNOWN"
} }
fun Any?.log(prefix: String? = null) { enum class LogLevel(value: Int) {
prefix?.let { INFO(LOG_LEVEL_INFO),
Log.d("FFA", "${logClassName()} - $prefix: $this") DEBUG(Log.LOG_LEVEL_ALL),
} ?: Log.d("FFA", "${logClassName()} - $this") ERROR(LOG_LEVEL_ERROR)
}
fun Any?.logError(prefix: String? = null) = this.log(prefix, LogLevel.ERROR)
fun Any?.logInfo(prefix: String? = null) = this.log(prefix, LogLevel.INFO)
fun Any?.log(prefix: String? = null, logLevel: LogLevel = LogLevel.DEBUG) {
val tag = "FFA"
val message = "${logClassName()} - ${prefix?.let { "$it: " }}$this"
when (logLevel) {
LogLevel.DEBUG -> Log.d(tag, message)
LogLevel.INFO -> Log.i(tag, message)
LogLevel.ERROR -> Log.e(tag, message)
}
} }
fun maybeNormalizeUrl(rawUrl: String?): String? { fun maybeNormalizeUrl(rawUrl: String?): String? {

Loading…
Cancel
Save