-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into bump_aztec_2_1_4
- Loading branch information
Showing
116 changed files
with
3,521 additions
and
2,599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
WooCommerce-Wear/src/main/java/com/woocommerce/android/app/WooCommerceWear.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
package com.woocommerce.android.app | ||
|
||
import android.app.Application | ||
import com.automattic.android.tracks.crashlogging.CrashLogging | ||
import com.yarolegovich.wellsql.WellSql | ||
import dagger.Lazy | ||
import dagger.hilt.android.HiltAndroidApp | ||
import org.greenrobot.eventbus.Subscribe | ||
import org.greenrobot.eventbus.ThreadMode | ||
import org.wordpress.android.fluxc.persistence.WellSqlConfig | ||
import org.wordpress.android.fluxc.persistence.WellSqlConfig.Companion.ADDON_WOOCOMMERCE | ||
import org.wordpress.android.fluxc.utils.ErrorUtils.OnUnexpectedError | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
open class WooCommerceWear : Application() { | ||
|
||
@Inject | ||
lateinit var crashLogging: Lazy<CrashLogging> | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
WellSql.init(WellSqlConfig(applicationContext, ADDON_WOOCOMMERCE)) | ||
crashLogging.get().initialize() | ||
} | ||
|
||
@Suppress("unused") | ||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onUnexpectedError(event: OnUnexpectedError) { | ||
with(event) { | ||
crashLogging.get().sendReport(exception = exception, message = "FluxC: ${exception.message}: $description") | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...erce-Wear/src/main/java/com/woocommerce/android/wear/crashlogging/FluxCCrashLoggerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.woocommerce.android.wear.crashlogging | ||
|
||
import com.automattic.android.tracks.crashlogging.CrashLogging | ||
import org.wordpress.android.fluxc.logging.FluxCCrashLogger | ||
|
||
class FluxCCrashLoggerImpl(private val crashLogging: CrashLogging) : FluxCCrashLogger { | ||
override fun recordEvent(message: String, category: String?) { | ||
crashLogging.recordEvent(message, category) | ||
} | ||
|
||
override fun recordException(exception: Throwable, category: String?) { | ||
crashLogging.recordException(exception, category) | ||
} | ||
|
||
override fun sendReport(exception: Throwable?, tags: Map<String, String>, message: String?) { | ||
crashLogging.sendReport(exception, tags, message) | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...src/main/java/com/woocommerce/android/wear/crashlogging/WCWearCrashLoggingDataProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.woocommerce.android.wear.crashlogging | ||
|
||
import com.automattic.android.tracks.crashlogging.CrashLoggingDataProvider | ||
import com.automattic.android.tracks.crashlogging.CrashLoggingUser | ||
import com.automattic.android.tracks.crashlogging.EventLevel | ||
import com.automattic.android.tracks.crashlogging.ExtraKnownKey | ||
import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig | ||
import com.automattic.android.tracks.crashlogging.ReleaseName | ||
import com.woocommerce.android.BuildConfig | ||
import com.woocommerce.android.wear.di.AppCoroutineScope | ||
import com.woocommerce.android.wear.settings.SettingsRepository | ||
import com.woocommerce.android.wear.ui.login.LoginRepository | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.launch | ||
import org.greenrobot.eventbus.Subscribe | ||
import org.greenrobot.eventbus.ThreadMode | ||
import org.wordpress.android.fluxc.Dispatcher | ||
import org.wordpress.android.fluxc.model.AccountModel | ||
import org.wordpress.android.fluxc.store.AccountStore | ||
import java.util.Locale | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class WCWearCrashLoggingDataProvider @Inject constructor( | ||
@AppCoroutineScope private val appScope: CoroutineScope, | ||
private val accountStore: AccountStore, | ||
private val providedLocale: Locale, | ||
private val settingsRepository: SettingsRepository, | ||
loginRepository: LoginRepository, | ||
dispatcher: Dispatcher, | ||
) : CrashLoggingDataProvider { | ||
|
||
init { dispatcher.register(this) } | ||
|
||
private val crashLoggingUser = MutableStateFlow(accountStore.account?.toCrashLoggingUser()) | ||
|
||
override val user: Flow<CrashLoggingUser?> = crashLoggingUser | ||
override val sentryDSN: String = BuildConfig.WEAR_SENTRY_DSN | ||
override val buildType = BuildConfig.BUILD_TYPE | ||
override val enableCrashLoggingLogs = BuildConfig.DEBUG | ||
override val releaseName: ReleaseName = if (BuildConfig.DEBUG) { | ||
ReleaseName.SetByApplication(DEBUG_RELEASE_NAME) | ||
} else { | ||
ReleaseName.SetByTracksLibrary | ||
} | ||
override val locale: Locale get() = providedLocale | ||
|
||
@Suppress("unused", "unused_parameter") | ||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
fun onAccountChanged(event: AccountStore.OnAccountChanged) { | ||
appScope.launch { | ||
crashLoggingUser.emit(accountStore.account.toCrashLoggingUser()) | ||
} | ||
} | ||
|
||
override fun provideExtrasForEvent( | ||
currentExtras: Map<ExtraKnownKey, String>, | ||
eventLevel: EventLevel | ||
) = emptyMap<ExtraKnownKey, String>() | ||
|
||
override fun shouldDropWrappingException(module: String, type: String, value: String) = false | ||
|
||
override val applicationContextProvider: Flow<Map<String, String>> = | ||
loginRepository.selectedSiteFlow | ||
.map { site -> | ||
site?.let { | ||
mutableMapOf<String, String>( | ||
SITE_URL_KEY to site.url | ||
).apply { | ||
site.siteId.takeIf { it != 0L }?.toString()?.let { | ||
this[SITE_ID_KEY] = it | ||
} | ||
} | ||
}.orEmpty() | ||
} | ||
|
||
override val performanceMonitoringConfig: PerformanceMonitoringConfig | ||
get() = PerformanceMonitoringConfig.Disabled | ||
|
||
override fun crashLoggingEnabled() = settingsRepository.crashReportEnabled.value | ||
|
||
override fun extraKnownKeys(): List<ExtraKnownKey> = emptyList() | ||
|
||
private fun AccountModel.toCrashLoggingUser(): CrashLoggingUser? { | ||
if (userId == 0L) return null | ||
|
||
return CrashLoggingUser( | ||
userID = userId.toString(), | ||
email = email, | ||
username = userName | ||
) | ||
} | ||
|
||
companion object { | ||
const val SITE_ID_KEY = "site_id" | ||
const val SITE_URL_KEY = "site_url" | ||
const val DEBUG_RELEASE_NAME = "debug" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
WooCommerce-Wear/src/main/java/com/woocommerce/android/wear/di/CrashLoggingModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.woocommerce.android.wear.di | ||
|
||
import android.app.Application | ||
import com.automattic.android.tracks.crashlogging.CrashLogging | ||
import com.automattic.android.tracks.crashlogging.CrashLoggingDataProvider | ||
import com.automattic.android.tracks.crashlogging.CrashLoggingProvider | ||
import com.woocommerce.android.wear.crashlogging.FluxCCrashLoggerImpl | ||
import com.woocommerce.android.wear.crashlogging.WCWearCrashLoggingDataProvider | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.wordpress.android.fluxc.logging.FluxCCrashLogger | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class CrashLoggingModule { | ||
companion object { | ||
@Provides | ||
@Singleton | ||
fun provideCrashLogging( | ||
context: Application, | ||
crashLoggingDataProvider: CrashLoggingDataProvider, | ||
@AppCoroutineScope appScope: CoroutineScope | ||
): CrashLogging { | ||
return CrashLoggingProvider.createInstance(context, crashLoggingDataProvider, appScope) | ||
} | ||
|
||
@Provides | ||
fun provideFluxCCrashLogger(crashLogging: CrashLogging): FluxCCrashLogger { | ||
return FluxCCrashLoggerImpl(crashLogging) | ||
} | ||
} | ||
|
||
@Binds | ||
abstract fun bindCrashLoggingDataProvider(dataProvider: WCWearCrashLoggingDataProvider): CrashLoggingDataProvider | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
WooCommerce-Wear/src/main/java/com/woocommerce/android/wear/settings/AppSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.woocommerce.android.wear.settings | ||
|
||
import android.content.SharedPreferences | ||
import com.woocommerce.commons.prefs.PreferenceUtils | ||
|
||
sealed class AppSettings<T> { | ||
abstract var value: T | ||
abstract val key: String | ||
|
||
data class CrashReportEnabledSettings( | ||
private val preferences: SharedPreferences | ||
) : AppSettings<Boolean>() { | ||
override val key = this::class.simpleName.orEmpty() | ||
|
||
override var value: Boolean | ||
get() = PreferenceUtils.getBoolean(preferences, key, true) | ||
set(value) = PreferenceUtils.setBoolean(preferences, key, value) | ||
} | ||
} |
Oops, something went wrong.