decoupling debug receiver from the variants by introducing vector layer interface
This commit is contained in:
parent
7e7b98a3c1
commit
e02cf61f2f
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* 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 im.vector.app.features.debug.di
|
||||||
|
|
||||||
|
import dagger.Binds
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import im.vector.app.core.platform.DebugReceiver
|
||||||
|
import im.vector.app.receivers.VectorDebugReceiver
|
||||||
|
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
@Module
|
||||||
|
abstract class DebugModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindsDebugReceiver(receiver: VectorDebugReceiver): DebugReceiver
|
||||||
|
}
|
@ -23,13 +23,23 @@ import android.content.IntentFilter
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
import im.vector.app.core.di.DefaultSharedPreferences
|
||||||
|
import im.vector.app.core.platform.DebugReceiver
|
||||||
import im.vector.app.core.utils.lsFiles
|
import im.vector.app.core.utils.lsFiles
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receiver to handle some command from ADB
|
* Receiver to handle some command from ADB
|
||||||
*/
|
*/
|
||||||
class DebugReceiver : BroadcastReceiver() {
|
class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugReceiver {
|
||||||
|
|
||||||
|
override fun register(context: Context) {
|
||||||
|
context.registerReceiver(this, getIntentFilter(context))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun unregister(context: Context) {
|
||||||
|
context.unregisterReceiver(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
Timber.v("Received debug action: ${intent.action}")
|
Timber.v("Received debug action: ${intent.action}")
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* 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 im.vector.app.core.platform
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
interface DebugReceiver {
|
||||||
|
fun register(context: Context)
|
||||||
|
fun unregister(context: Context)
|
||||||
|
}
|
@ -91,7 +91,7 @@ import im.vector.app.features.settings.FontScalePreferencesImpl
|
|||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.features.themes.ActivityOtherThemes
|
import im.vector.app.features.themes.ActivityOtherThemes
|
||||||
import im.vector.app.features.themes.ThemeUtils
|
import im.vector.app.features.themes.ThemeUtils
|
||||||
import im.vector.app.receivers.DebugReceiver
|
import im.vector.app.receivers.VectorDebugReceiver
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
@ -160,6 +160,8 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
|||||||
@Inject lateinit var rageShake: RageShake
|
@Inject lateinit var rageShake: RageShake
|
||||||
@Inject lateinit var buildMeta: BuildMeta
|
@Inject lateinit var buildMeta: BuildMeta
|
||||||
@Inject lateinit var fontScalePreferences: FontScalePreferences
|
@Inject lateinit var fontScalePreferences: FontScalePreferences
|
||||||
|
// For debug only
|
||||||
|
@Inject lateinit var debugReceiver: VectorDebugReceiver
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var vectorFeatures: VectorFeatures
|
lateinit var vectorFeatures: VectorFeatures
|
||||||
@ -176,9 +178,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
|||||||
|
|
||||||
private var savedInstanceState: Bundle? = null
|
private var savedInstanceState: Bundle? = null
|
||||||
|
|
||||||
// For debug only
|
|
||||||
private var debugReceiver: DebugReceiver? = null
|
|
||||||
|
|
||||||
private val restorables = ArrayList<Restorable>()
|
private val restorables = ArrayList<Restorable>()
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context) {
|
override fun attachBaseContext(base: Context) {
|
||||||
@ -418,13 +417,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
|||||||
if (this !is BugReportActivity && vectorPreferences.useRageshake()) {
|
if (this !is BugReportActivity && vectorPreferences.useRageshake()) {
|
||||||
rageShake.start()
|
rageShake.start()
|
||||||
}
|
}
|
||||||
DebugReceiver
|
debugReceiver.register(this)
|
||||||
.getIntentFilter(this)
|
|
||||||
.takeIf { buildMeta.isDebug }
|
|
||||||
?.let {
|
|
||||||
debugReceiver = DebugReceiver()
|
|
||||||
registerReceiver(debugReceiver, it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val postResumeScheduledActions = mutableListOf<() -> Unit>()
|
private val postResumeScheduledActions = mutableListOf<() -> Unit>()
|
||||||
@ -454,11 +447,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
|||||||
Timber.i("onPause Activity ${javaClass.simpleName}")
|
Timber.i("onPause Activity ${javaClass.simpleName}")
|
||||||
|
|
||||||
rageShake.stop()
|
rageShake.stop()
|
||||||
|
debugReceiver.unregister(this)
|
||||||
debugReceiver?.let {
|
|
||||||
unregisterReceiver(debugReceiver)
|
|
||||||
debugReceiver = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
|
38
vector/src/release/java/im/vector/app/core/di/DebugModule.kt
Normal file
38
vector/src/release/java/im/vector/app/core/di/DebugModule.kt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* 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 im.vector.app.features.debug.di
|
||||||
|
|
||||||
|
import dagger.Binds
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import im.vector.app.core.platform.DebugReceiver
|
||||||
|
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
@Module
|
||||||
|
object DebugModule {
|
||||||
|
@Provides
|
||||||
|
fun providesDebugReceiver() = object: DebugReceiver {
|
||||||
|
override fun register(context: Context) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun unregister(context: Context) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user