mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Replaces AppBuildConfig
This commit is contained in:
parent
4cebfa13e8
commit
d14570dbea
8 changed files with 160 additions and 31 deletions
|
@ -1700,8 +1700,8 @@
|
|||
<string name="push_gateway_item_app_id">App ID:</string>
|
||||
<string name="push_gateway_item_push_key">Push Key:</string>
|
||||
<string name="push_gateway_item_app_display_name">App Display Name:</string>
|
||||
<string name="push_gateway_item_device_name">Device Display Name:</string>
|
||||
<string name="push_gateway_item_device_id">Device ID:</string>
|
||||
<string name="push_gateway_item_device_name">Session Display Name:</string>
|
||||
<string name="push_gateway_item_device_id">Session ID:</string>
|
||||
<string name="push_gateway_item_url">Url:</string>
|
||||
<string name="push_gateway_item_format">Format:</string>
|
||||
<string name="push_gateway_item_profile_tag">Profile tag:</string>
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.device
|
||||
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||
import javax.inject.Inject
|
||||
|
||||
interface GetDeviceInfoUseCase {
|
||||
|
||||
fun execute(): CryptoDeviceInfo
|
||||
}
|
||||
|
||||
class DefaultGetDeviceInfoUseCase @Inject constructor(
|
||||
private val activeSessionHolder: ActiveSessionHolder
|
||||
) : GetDeviceInfoUseCase {
|
||||
|
||||
override fun execute(): CryptoDeviceInfo {
|
||||
return activeSessionHolder.getActiveSession().cryptoService().getMyDevice()
|
||||
}
|
||||
}
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package im.vector.app.core.pushers
|
||||
|
||||
import im.vector.app.AppBuildConfig
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.device.GetDeviceInfoUseCase
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.resources.AppNameProvider
|
||||
import im.vector.app.core.resources.LocaleProvider
|
||||
|
@ -35,6 +35,7 @@ class PushersManager @Inject constructor(
|
|||
private val localeProvider: LocaleProvider,
|
||||
private val stringProvider: StringProvider,
|
||||
private val appNameProvider: AppNameProvider,
|
||||
private val getDeviceInfoUseCase: GetDeviceInfoUseCase,
|
||||
) {
|
||||
suspend fun testPush() {
|
||||
val currentSession = activeSessionHolder.getActiveSession()
|
||||
|
@ -64,12 +65,12 @@ class PushersManager @Inject constructor(
|
|||
pushKey: String,
|
||||
gateway: String
|
||||
) = HttpPusher(
|
||||
pushKey,
|
||||
pushkey = pushKey,
|
||||
appId = stringProvider.getString(R.string.pusher_app_id),
|
||||
profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + abs(activeSessionHolder.getActiveSession().myUserId.hashCode()),
|
||||
lang = localeProvider.current().language,
|
||||
appDisplayName = appNameProvider.getAppName(),
|
||||
deviceDisplayName = AppBuildConfig.getModel(),
|
||||
deviceDisplayName = getDeviceInfoUseCase.execute().displayName().orEmpty(),
|
||||
url = gateway,
|
||||
enabled = true,
|
||||
deviceId = activeSessionHolder.getActiveSession().sessionParams.deviceId ?: "MOBILE",
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.device
|
||||
|
||||
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||
import im.vector.app.test.fakes.FakeCryptoService
|
||||
import im.vector.app.test.fakes.FakeSession
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.junit.Test
|
||||
|
||||
class DefaultGetDeviceInfoUseCaseTest {
|
||||
|
||||
private val cryptoService = FakeCryptoService()
|
||||
private val session = FakeSession(fakeCryptoService = cryptoService)
|
||||
private val activeSessionHolder = FakeActiveSessionHolder(session)
|
||||
|
||||
private val getDeviceInfoUseCase = DefaultGetDeviceInfoUseCase(activeSessionHolder.instance)
|
||||
|
||||
@Test
|
||||
fun `when execute, then get crypto device info`() {
|
||||
|
||||
val result = getDeviceInfoUseCase.execute()
|
||||
|
||||
result shouldBeEqualTo cryptoService.cryptoDeviceInfo
|
||||
}
|
||||
}
|
|
@ -16,20 +16,20 @@
|
|||
|
||||
package im.vector.app.core.pushers
|
||||
|
||||
import im.vector.app.AppBuildConfig
|
||||
import im.vector.app.R
|
||||
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||
import im.vector.app.test.fakes.FakeAppNameProvider
|
||||
import im.vector.app.test.fakes.FakeGetDeviceInfoUseCase
|
||||
import im.vector.app.test.fakes.FakeLocaleProvider
|
||||
import im.vector.app.test.fakes.FakePushersService
|
||||
import im.vector.app.test.fakes.FakeSession
|
||||
import im.vector.app.test.fakes.FakeStringProvider
|
||||
import io.mockk.every
|
||||
import im.vector.app.test.fixtures.CryptoDeviceInfoFixture.aCryptoDeviceInfo
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.session.crypto.model.UnsignedDeviceInfo
|
||||
import org.matrix.android.sdk.api.session.pushers.HttpPusher
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
|
||||
|
@ -41,6 +41,7 @@ class PushersManagerTest {
|
|||
private val stringProvider = FakeStringProvider()
|
||||
private val localeProvider = FakeLocaleProvider()
|
||||
private val appNameProvider = FakeAppNameProvider()
|
||||
private val getDeviceInfoUseCase = FakeGetDeviceInfoUseCase()
|
||||
|
||||
private val pushersManager = PushersManager(
|
||||
mockk(),
|
||||
|
@ -48,13 +49,9 @@ class PushersManagerTest {
|
|||
localeProvider,
|
||||
stringProvider.instance,
|
||||
appNameProvider,
|
||||
getDeviceInfoUseCase,
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockkObject(AppBuildConfig)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when enqueueRegisterPusher, then HttpPusher created and enqueued`() {
|
||||
val pushKey = "abc"
|
||||
|
@ -65,21 +62,24 @@ class PushersManagerTest {
|
|||
stringProvider.given(R.string.pusher_app_id, pusherAppId)
|
||||
localeProvider.givenCurrent(Locale.UK)
|
||||
appNameProvider.givenAppName(appName)
|
||||
every { AppBuildConfig.getModel() } returns deviceDisplayName
|
||||
getDeviceInfoUseCase.givenDeviceInfo(aCryptoDeviceInfo(unsigned = UnsignedDeviceInfo(deviceDisplayName)))
|
||||
val expectedHttpPusher = HttpPusher(
|
||||
pushkey = pushKey,
|
||||
appId = pusherAppId,
|
||||
profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + abs(session.myUserId.hashCode()),
|
||||
lang = Locale.UK.language,
|
||||
appDisplayName = appName,
|
||||
deviceDisplayName = deviceDisplayName,
|
||||
url = gateway,
|
||||
enabled = true,
|
||||
deviceId = session.sessionParams.deviceId!!,
|
||||
append = false,
|
||||
withEventIdOnly = true,
|
||||
)
|
||||
|
||||
pushersManager.enqueueRegisterPusher(pushKey, gateway)
|
||||
|
||||
val httpPusher = pushersService.verifyEnqueueAddHttpPusher()
|
||||
httpPusher.pushkey shouldBeEqualTo pushKey
|
||||
httpPusher.appId shouldBeEqualTo pusherAppId
|
||||
httpPusher.profileTag shouldBeEqualTo DEFAULT_PUSHER_FILE_TAG + "_" + abs(session.myUserId.hashCode())
|
||||
httpPusher.lang shouldBeEqualTo Locale.UK.language
|
||||
httpPusher.appDisplayName shouldBeEqualTo appName
|
||||
httpPusher.deviceDisplayName shouldBeEqualTo deviceDisplayName
|
||||
httpPusher.enabled shouldBeEqualTo true
|
||||
httpPusher.deviceId shouldBeEqualTo session.sessionParams.deviceId
|
||||
httpPusher.append shouldBeEqualTo false
|
||||
httpPusher.withEventIdOnly shouldBeEqualTo true
|
||||
httpPusher.url shouldBeEqualTo gateway
|
||||
httpPusher shouldBeEqualTo expectedHttpPusher
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package im.vector.app.test.fakes
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import im.vector.app.test.fixtures.CryptoDeviceInfoFixture.aCryptoDeviceInfo
|
||||
import io.mockk.mockk
|
||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||
|
@ -32,6 +33,7 @@ class FakeCryptoService(
|
|||
var cryptoDeviceInfos = mutableMapOf<String, CryptoDeviceInfo>()
|
||||
var cryptoDeviceInfoWithIdLiveData: MutableLiveData<Optional<CryptoDeviceInfo>> = MutableLiveData()
|
||||
var myDevicesInfoWithIdLiveData: MutableLiveData<Optional<DeviceInfo>> = MutableLiveData()
|
||||
var cryptoDeviceInfo = aCryptoDeviceInfo()
|
||||
|
||||
override fun crossSigningService() = fakeCrossSigningService
|
||||
|
||||
|
@ -50,4 +52,6 @@ class FakeCryptoService(
|
|||
override fun getLiveCryptoDeviceInfoWithId(deviceId: String) = cryptoDeviceInfoWithIdLiveData
|
||||
|
||||
override fun getMyDevicesInfoLive(deviceId: String) = myDevicesInfoWithIdLiveData
|
||||
|
||||
override fun getMyDevice() = cryptoDeviceInfo
|
||||
}
|
||||
|
|
|
@ -14,13 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app
|
||||
package im.vector.app.test.fakes
|
||||
|
||||
import android.os.Build
|
||||
import im.vector.app.core.device.GetDeviceInfoUseCase
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||
|
||||
object AppBuildConfig {
|
||||
class FakeGetDeviceInfoUseCase : GetDeviceInfoUseCase by mockk() {
|
||||
|
||||
fun getModel(): String {
|
||||
return Build.MODEL
|
||||
fun givenDeviceInfo(cryptoDeviceInfo: CryptoDeviceInfo) {
|
||||
every { execute() } returns cryptoDeviceInfo
|
||||
}
|
||||
}
|
46
vector/src/test/java/im/vector/app/test/fixtures/CryptoDeviceInfoFixture.kt
vendored
Normal file
46
vector/src/test/java/im/vector/app/test/fixtures/CryptoDeviceInfoFixture.kt
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.test.fixtures
|
||||
|
||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
|
||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||
import org.matrix.android.sdk.api.session.crypto.model.UnsignedDeviceInfo
|
||||
|
||||
object CryptoDeviceInfoFixture {
|
||||
|
||||
fun aCryptoDeviceInfo(
|
||||
deviceId: String = "",
|
||||
userId: String = "",
|
||||
algorithms: List<String>? = null,
|
||||
keys: Map<String, String>? = null,
|
||||
signatures: Map<String, Map<String, String>>? = null,
|
||||
unsigned: UnsignedDeviceInfo? = null,
|
||||
trustLevel: DeviceTrustLevel? = null,
|
||||
isBlocked: Boolean = false,
|
||||
firstTimeSeenLocalTs: Long? = null,
|
||||
) = CryptoDeviceInfo(
|
||||
deviceId,
|
||||
userId,
|
||||
algorithms,
|
||||
keys,
|
||||
signatures,
|
||||
unsigned,
|
||||
trustLevel,
|
||||
isBlocked,
|
||||
firstTimeSeenLocalTs,
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue