Skip to content

Commit

Permalink
feat: add configuration to force websocket (WPB-3311) (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina committed Aug 1, 2023
1 parent f0c3ac8 commit 8bbd3f9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import android.content.Context
import android.os.Build
import com.wire.android.BuildConfig
import com.wire.android.datastore.GlobalDataStore
import com.wire.android.util.extension.isGoogleServicesAvailable
import com.wire.android.util.isWebsocketEnabledByDefault
import com.wire.kalium.logic.featureFlags.BuildFileRestrictionState
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import dagger.Module
Expand Down Expand Up @@ -69,7 +69,7 @@ class KaliumConfigsModule {
wipeOnCookieInvalid = BuildConfig.WIPE_ON_COOKIE_INVALID,
wipeOnDeviceRemoval = BuildConfig.WIPE_ON_DEVICE_REMOVAL,
wipeOnRootedDevice = BuildConfig.WIPE_ON_ROOTED_DEVICE,
isWebSocketEnabledByDefault = !context.isGoogleServicesAvailable()
isWebSocketEnabledByDefault = isWebsocketEnabledByDefault(context)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.wire.android.ui.common.topappbar.WireCenterAlignedTopAppBar
import com.wire.android.ui.home.conversations.details.options.ArrowType
import com.wire.android.ui.home.conversations.details.options.GroupConversationOptionsItem
import com.wire.android.ui.home.conversations.details.options.SwitchState
import com.wire.android.util.extension.isGoogleServicesAvailable
import com.wire.android.util.isWebsocketEnabledByDefault

@Composable
fun NetworkSettingsScreen(networkSettingsViewModel: NetworkSettingsViewModel = hiltViewModel()) {
Expand Down Expand Up @@ -68,34 +68,24 @@ fun NetworkSettingsScreenContent(
.fillMaxSize()
.padding(internalPadding)
) {
GroupConversationOptionsItem(
title = stringResource(R.string.settings_keep_connection_to_websocket),
subtitle = stringResource(
R.string.settings_keep_connection_to_websocket_description,
backendName
),
switchState = getSwitchState(isWebSocketEnabled, setWebSocketState),
arrowType = ArrowType.NONE
)
if (!isWebsocketEnabledByDefault(LocalContext.current)) {
GroupConversationOptionsItem(
title = stringResource(R.string.settings_keep_connection_to_websocket),
subtitle = stringResource(
R.string.settings_keep_connection_to_websocket_description,
backendName
),
switchState = SwitchState.Enabled(
value = isWebSocketEnabled,
onCheckedChange = setWebSocketState
),
arrowType = ArrowType.NONE
)
}
}
}
}

@Composable
private fun getSwitchState(isWebSocketEnabled: Boolean, setWebSocketState: (Boolean) -> Unit): SwitchState {
val context = LocalContext.current
return if (context.isGoogleServicesAvailable()) {
SwitchState.Enabled(
value = isWebSocketEnabled,
onCheckedChange = setWebSocketState
)
} else {
SwitchState.Disabled(
value = isWebSocketEnabled,
)
}
}

@Composable
@Preview
fun PreviewNetworkSettingsScreen() {
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/kotlin/com/wire/android/util/WebsocketHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.util

import android.content.Context
import com.wire.android.BuildConfig
import com.wire.android.util.extension.isGoogleServicesAvailable

/**
* If [BuildConfig.WEBSOCKET_ENABLED_BY_DEFAULT] is true, the websocket should be enabled by default always.
* Otherwise, it should be enabled by default only if Google Play Services are not available.
*/
fun isWebsocketEnabledByDefault(context: Context) =
BuildConfig.WEBSOCKET_ENABLED_BY_DEFAULT || !context.isGoogleServicesAvailable()
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/customization/FeatureConfigs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum class FeatureConfigs(val value: String, val configType: ConfigType) {
ENABLE_GUEST_ROOM_LINK("enable_guest_room_link", ConfigType.BOOLEAN),
UPDATE_APP_URL("update_app_url", ConfigType.STRING),
ENABLE_BLACKLIST("enable_blacklist", ConfigType.BOOLEAN),
WEBSOCKET_ENABLED_BY_DEFAULT("websocket_enabled_by_default", ConfigType.BOOLEAN),

/**
* Security/Cryptography stuff
Expand Down
1 change: 1 addition & 0 deletions default.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"wipe_on_cookie_invalid": false,
"wipe_on_device_removal": false,
"wipe_on_rooted_device": false,
"websocket_enabled_by_default": false,

"firebase_push_sender_id": "782078216207",
"firebase_app_id": "1:782078216207:android:d3db2443512d2055",
Expand Down

0 comments on commit 8bbd3f9

Please sign in to comment.