Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Flipper #6300

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6300.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Setup [Flipper](https://fbflipper.com/)
4 changes: 4 additions & 0 deletions dependencies_groups.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ext.groups = [
],
group: [
'com.android',
'com.android.ndk.thirdparty',
'com.android.tools',
'com.google.firebase',
'com.google.testing.platform',
Expand All @@ -52,6 +53,7 @@ ext.groups = [
'com.dropbox.core',
'com.soywiz.korlibs.korte',
'com.facebook.fbjni',
'com.facebook.flipper',
'com.facebook.fresco',
'com.facebook.infer.annotation',
'com.facebook.soloader',
Expand Down Expand Up @@ -93,6 +95,7 @@ ext.groups = [
'com.ibm.icu',
'com.jakewharton.android.repackaged',
'com.jakewharton.timber',
'com.kgurgul.flipper',
'com.linkedin.dexmaker',
'com.mapbox.mapboxsdk',
'com.nulab-inc',
Expand Down Expand Up @@ -168,6 +171,7 @@ ext.groups = [
'org.glassfish.jaxb',
'org.hamcrest',
'org.jacoco',
'org.java-websocket',
'org.jetbrains',
'org.jetbrains.dokka',
'org.jetbrains.intellij.deps',
Expand Down
57 changes: 57 additions & 0 deletions docs/flipper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Flipper

<!--- TOC -->

* [Introduction](#introduction)
* [Setup](#setup)
* [Troubleshoot](#troubleshoot)
* [No device found issue](#no-device-found-issue)
* [Diagnostic Activity](#diagnostic-activity)
* [Other](#other)
* [Links](#links)

<!--- END -->

## Introduction

[Flipper](https://fbflipper.com) is a powerful tool from Meta, which allow to inspect the running application details and states from your computer.

Flipper is configured in the Element Android project to let the developers be able to:
- inspect all the Realm databases content;
- do layout inspection;
- see the crash logs;
- see the logcat;
- see all the network requests;
- see all the SharedPreferences;
- take screenshots and record videos of the device;
- and more!

## Setup

- Install Flipper on your computer. Follow instructions here: https://fbflipper.com/docs/getting-started/index/
- Run the debug version of Element on an emulator or on a real device.

### Troubleshoot

#### No device found issue

The configuration of the Flipper application has to be updated. The issue has been asked and answered here: https://stackoverflow.com/questions/71744103/android-emulator-unable-to-connect-to-flipper/72608113#72608113

#### Diagnostic Activity

Flipper comes with a Diagnostic Activity that you can start from command line using:

```shell
adb shell am start -n im.vector.app.debug/com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity
```

It provides some log which can help to figure out what's going on client side.

#### Other

https://fbflipper.com/docs/getting-started/troubleshooting/android/ may help.

## Links

- https://fbflipper.com
- Realm Plugin for Flipper: https://github.com/kamgurgul/Flipper-Realm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dagger.BindsInstance
import dagger.Component
import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.internal.auth.AuthModule
import org.matrix.android.sdk.internal.debug.DebugModule
import org.matrix.android.sdk.internal.di.MatrixComponent
import org.matrix.android.sdk.internal.di.MatrixModule
import org.matrix.android.sdk.internal.di.MatrixScope
Expand All @@ -36,6 +37,7 @@ import org.matrix.android.sdk.internal.util.system.SystemModule
NetworkModule::class,
AuthModule::class,
RawModule::class,
DebugModule::class,
SettingsModule::class,
SystemModule::class
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.BuildConfig
import org.matrix.android.sdk.api.auth.AuthenticationService
import org.matrix.android.sdk.api.auth.HomeServerHistoryService
import org.matrix.android.sdk.api.debug.DebugService
import org.matrix.android.sdk.api.legacy.LegacySessionImporter
import org.matrix.android.sdk.api.network.ApiInterceptorListener
import org.matrix.android.sdk.api.network.ApiPath
Expand Down Expand Up @@ -54,6 +55,7 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) {
@Inject internal lateinit var legacySessionImporter: LegacySessionImporter
@Inject internal lateinit var authenticationService: AuthenticationService
@Inject internal lateinit var rawService: RawService
@Inject internal lateinit var debugService: DebugService
@Inject internal lateinit var userAgentHolder: UserAgentHolder
@Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver
@Inject internal lateinit var olmManager: OlmManager
Expand Down Expand Up @@ -93,6 +95,11 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) {
*/
fun rawService() = rawService

/**
* Return the DebugService.
*/
fun debugService() = debugService

/**
* Return the LightweightSettingsStorage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.matrix.android.sdk.api

import okhttp3.ConnectionSpec
import okhttp3.Interceptor
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
import java.net.Proxy

Expand Down Expand Up @@ -65,4 +66,8 @@ data class MatrixConfiguration(
* Thread messages default enable/disabled value.
*/
val threadMessagesEnabledDefault: Boolean = false,
/**
* List of network interceptors, they will be added when building an OkHttp client.
*/
val networkInterceptors: List<Interceptor> = emptyList(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd instead allow to provide an okhttp client. We'll be able to use okhttpClient.newBuilder().
If the app is using his own okhttp it'll allow to share resources.

Copy link
Member Author

@bmarty bmarty Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my latest commit 5c84fdc, the interceptors provided by the configuration have to be added at the end, to ensure to see all the request headers.
Providing on OkHttp client make sense though, maybe for another dedicated PR?

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.android.sdk.api.debug

import io.realm.RealmConfiguration

/**
* Useful methods to access to some private data managed by the SDK.
*/
interface DebugService {
/**
* Get all the available Realm Configuration.
*/
fun getAllRealmConfigurations(): List<RealmConfiguration>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could instead returns a list of flipper plugin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Matrix SDK does not know what a Flipper plugin is, only the debug version of module vector knows it. Also there is only one Plugin to set up for all the RealmDatabase inspection.


/**
* Prints out info on DB size to logcat.
*/
fun logDbUsageInfo()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: it should probably return a String rather than printing things on logcat, but this is out of scope of this PR.

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.matrix.android.sdk.api.session

import androidx.annotation.MainThread
import io.realm.RealmConfiguration
import okhttp3.OkHttpClient
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.auth.data.SessionParams
Expand Down Expand Up @@ -334,7 +335,12 @@ interface Session {
fun getUiaSsoFallbackUrl(authenticationSessionId: String): String

/**
* Maintenance API, allows to print outs info on DB size to logcat.
* Debug API, will print out info on DB size to logcat.
*/
fun logDbUsageInfo()

/**
* Debug API, return the list of all RealmConfiguration used by this session.
*/
fun getRealmConfigurations(): List<RealmConfiguration>
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ interface CryptoService {
fun getSharedWithInfo(roomId: String?, sessionId: String): MXUsersDevicesMap<Int>
fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent?

fun logDbUsageInfo()

/**
* Perform any background tasks that can be done before a message is ready to
* send, in order to speed up sending of the message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ internal class SessionManager @Inject constructor(
return getOrCreateSessionComponent(sessionParams)
}

fun getLastSession(): Session? {
val sessionParams = sessionParamsStore.getLast()
return sessionParams?.let {
getOrCreateSession(it)
}
}

fun getOrCreateSession(sessionParams: SessionParams): Session {
return getOrCreateSessionComponent(sessionParams).session()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ internal class DefaultAuthenticationService @Inject constructor(
}

override fun getLastAuthenticatedSession(): Session? {
val sessionParams = sessionParamsStore.getLast()
return sessionParams?.let {
sessionManager.getOrCreateSession(it)
}
return sessionManager.getLastSession()
}

override suspend fun getLoginFlowOfSession(sessionId: String): LoginFlowResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,6 @@ internal class DefaultCryptoService @Inject constructor(
return cryptoStore.getWithHeldMegolmSession(roomId, sessionId)
}

override fun logDbUsageInfo() {
cryptoStore.logDbUsageInfo()
}

override fun prepareToEncrypt(roomId: String, callback: MatrixCallback<Unit>) {
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
Timber.tag(loggerTag.value).d("prepareToEncrypt() roomId:$roomId Check room members up to date")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,5 @@ internal interface IMXCryptoStore {
fun setDeviceKeysUploaded(uploaded: Boolean)
fun areDeviceKeysUploaded(): Boolean
fun tidyUpDataBase()
fun logDbUsageInfo()
fun getOutgoingRoomKeyRequests(inStates: Set<OutgoingRoomKeyRequestState>): List<OutgoingKeyRequest>
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import org.matrix.android.sdk.internal.crypto.store.db.query.get
import org.matrix.android.sdk.internal.crypto.store.db.query.getById
import org.matrix.android.sdk.internal.crypto.store.db.query.getOrCreate
import org.matrix.android.sdk.internal.crypto.util.RequestIdHelper
import org.matrix.android.sdk.internal.database.tools.RealmDebugTools
import org.matrix.android.sdk.internal.di.CryptoDatabase
import org.matrix.android.sdk.internal.di.DeviceId
import org.matrix.android.sdk.internal.di.MoshiProvider
Expand Down Expand Up @@ -1709,11 +1708,4 @@ internal class RealmCryptoStore @Inject constructor(
// Can we do something for WithHeldSessionEntity?
}
}

/**
* Prints out database info.
*/
override fun logDbUsageInfo() {
RealmDebugTools(realmConfiguration).logInfo("Crypto")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.matrix.android.sdk.internal.debug

import dagger.Binds
import dagger.Module
import org.matrix.android.sdk.api.debug.DebugService

@Module
internal abstract class DebugModule {

@Binds
abstract fun bindDebugService(service: DefaultDebugService): DebugService
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.android.sdk.internal.debug

import io.realm.RealmConfiguration
import org.matrix.android.sdk.api.debug.DebugService
import org.matrix.android.sdk.internal.SessionManager
import org.matrix.android.sdk.internal.database.tools.RealmDebugTools
import org.matrix.android.sdk.internal.di.AuthDatabase
import org.matrix.android.sdk.internal.di.GlobalDatabase
import javax.inject.Inject

internal class DefaultDebugService @Inject constructor(
@AuthDatabase private val realmConfigurationAuth: RealmConfiguration,
@GlobalDatabase private val realmConfigurationGlobal: RealmConfiguration,
private val sessionManager: SessionManager,
) : DebugService {

override fun getAllRealmConfigurations(): List<RealmConfiguration> {
return sessionManager.getLastSession()?.getRealmConfigurations().orEmpty() +
realmConfigurationAuth +
realmConfigurationGlobal
}

override fun logDbUsageInfo() {
RealmDebugTools(realmConfigurationAuth).logInfo("Auth")
RealmDebugTools(realmConfigurationGlobal).logInfo("Global")
sessionManager.getLastSession()?.logDbUsageInfo()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
import org.matrix.android.sdk.internal.SessionManager
import org.matrix.android.sdk.internal.auth.AuthModule
import org.matrix.android.sdk.internal.auth.SessionParamsStore
import org.matrix.android.sdk.internal.debug.DebugModule
import org.matrix.android.sdk.internal.raw.RawModule
import org.matrix.android.sdk.internal.session.MockHttpInterceptor
import org.matrix.android.sdk.internal.session.TestInterceptor
Expand All @@ -49,6 +50,7 @@ import java.io.File
NetworkModule::class,
AuthModule::class,
RawModule::class,
DebugModule::class,
SettingsModule::class,
SystemModule::class,
NoOpTestModule::class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.internal.network.ApiInterceptor
import org.matrix.android.sdk.internal.network.TimeOutInterceptor
import org.matrix.android.sdk.internal.network.UserAgentInterceptor
import org.matrix.android.sdk.internal.network.httpclient.applyMatrixConfiguration
import org.matrix.android.sdk.internal.network.interceptors.CurlLoggingInterceptor
import org.matrix.android.sdk.internal.network.interceptors.FormattedJsonHttpLogger
import java.util.Collections
Expand Down Expand Up @@ -92,11 +93,9 @@ internal object NetworkModule {
if (BuildConfig.LOG_PRIVATE_DATA) {
addInterceptor(curlLoggingInterceptor)
}
matrixConfiguration.proxy?.let {
proxy(it)
}
}
.connectionSpecs(Collections.singletonList(spec))
.applyMatrixConfiguration(matrixConfiguration)
.build()
}

Expand Down
Loading