Skip to content

Commit

Permalink
Merge branch 'release/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Jul 30, 2020
2 parents a048f79 + 258acaf commit 7fddfa4
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 20 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Changes in Element 1.0.3 (2020-07-31)
===================================================

Features ✨:
- Support server admin option to disable E2EE for DMs / private rooms [users can still enable] (#1794)

Bugfix 🐛:
- Crash reported on playstore for HomeActivity launch (151 reports)

Changes in Element 1.0.2 (2020-07-29)
===================================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@ data class WellKnown(
val identityServer: WellKnownBaseConfig? = null,

@Json(name = "m.integrations")
val integrations: JsonDict? = null
val integrations: JsonDict? = null,

@Json(name = "im.vector.riot.e2ee")
val e2eAdminSetting: E2EWellKnownConfig? = null

)

@JsonClass(generateAdapter = true)
data class E2EWellKnownConfig(
@Json(name = "default")
val e2eDefault: Boolean = true
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ data class HomeServerCapabilities(
/**
* Default identity server url, provided in Wellknown
*/
val defaultIdentityServerUrl: String? = null
val defaultIdentityServerUrl: String? = null,
/**
* Option to allow homeserver admins to set the default E2EE behaviour back to disabled for DMs / private rooms
* (as it was before) for various environments where this is desired.
*/
val adminE2EByDefault: Boolean = true
) {
companion object {
const val MAX_UPLOAD_FILE_SIZE_UNKNOWN = -1L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package im.vector.matrix.android.internal.database

import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEntityFields
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
import io.realm.DynamicRealm
import io.realm.RealmMigration
Expand All @@ -28,6 +29,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
Timber.v("Migrating Realm Session from $oldVersion to $newVersion")

if (oldVersion <= 0) migrateTo1(realm)
if (oldVersion <= 1) migrateTo2(realm)
}

private fun migrateTo1(realm: DynamicRealm) {
Expand All @@ -40,4 +42,13 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
obj.setBoolean(RoomSummaryEntityFields.HAS_FAILED_SENDING, false)
}
}

private fun migrateTo2(realm: DynamicRealm) {
Timber.d("Step 1 -> 2")
realm.schema.get("HomeServerCapabilitiesEntity")
?.addField(HomeServerCapabilitiesEntityFields.ADMIN_E2_E_BY_DEFAULT, Boolean::class.java)
?.transform { obj ->
obj.setBoolean(HomeServerCapabilitiesEntityFields.ADMIN_E2_E_BY_DEFAULT, true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class SessionRealmConfigurationFactory @Inject constructor(
context: Context) {

companion object {
const val SESSION_STORE_SCHEMA_VERSION = 1L
const val SESSION_STORE_SCHEMA_VERSION = 2L
}

private val sharedPreferences = context.getSharedPreferences("im.vector.matrix.android.realm", Context.MODE_PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal object HomeServerCapabilitiesMapper {
canChangePassword = entity.canChangePassword,
maxUploadFileSize = entity.maxUploadFileSize,
lastVersionIdentityServerSupported = entity.lastVersionIdentityServerSupported,
defaultIdentityServerUrl = entity.defaultIdentityServerUrl
defaultIdentityServerUrl = entity.defaultIdentityServerUrl,
adminE2EByDefault = entity.adminE2EByDefault
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal open class HomeServerCapabilitiesEntity(
var maxUploadFileSize: Long = HomeServerCapabilities.MAX_UPLOAD_FILE_SIZE_UNKNOWN,
var lastVersionIdentityServerSupported: Boolean = false,
var defaultIdentityServerUrl: String? = null,
var adminE2EByDefault: Boolean = true,
var lastUpdatedTimestamp: Long = 0L
) : RealmObject() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(

if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) {
homeServerCapabilitiesEntity.defaultIdentityServerUrl = getWellknownResult.identityServerUrl

homeServerCapabilitiesEntity.adminE2EByDefault = getWellknownResult.wellKnown.e2eAdminSetting?.e2eDefault ?: true
// We are also checking for integration manager configurations
val config = configExtractor.extract(getWellknownResult.wellKnown)
if (config != null) {
Timber.v("Extracted integration config : $config")
realm.insertOrUpdate(config)
}
} else {
homeServerCapabilitiesEntity.adminE2EByDefault = true
}
homeServerCapabilitiesEntity.lastUpdatedTimestamp = Date().time
}
Expand Down
2 changes: 1 addition & 1 deletion vector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ androidExtensions {
// Note: 2 digits max for each value
ext.versionMajor = 1
ext.versionMinor = 0
ext.versionPatch = 2
ext.versionPatch = 3

static def getGitTimestamp() {
def cmd = 'git show -s --format=%ct'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
fun create(initialState: CreateDirectRoomViewState): CreateDirectRoomViewModel
}

init {
setState {
copy(
hsAdminHasDisabledE2E = !session.getHomeServerCapabilities().adminE2EByDefault
)
}
}

companion object : MvRxViewModelFactory<CreateDirectRoomViewModel, CreateDirectRoomViewState> {

@JvmStatic
Expand All @@ -63,7 +71,7 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
}.exhaustive
}
setDirectMessage()
enableEncryptionIfInvitedUsersSupportIt = true
enableEncryptionIfInvitedUsersSupportIt = session.getHomeServerCapabilities().adminE2EByDefault
}

session.rx()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.Uninitialized

data class CreateDirectRoomViewState(
val createAndInviteState: Async<String> = Uninitialized
val createAndInviteState: Async<String> = Uninitialized,
val hsAdminHasDisabledE2E: Boolean = false
) : MvRxState
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: SharedSecureStorageViewState): SharedSecureStorageViewModel? {
val activity: SharedSecureStorageActivity = viewModelContext.activity()
val args: SharedSecureStorageActivity.Args? = activity.intent.getParcelableExtra(MvRx.KEY_ARG)
return args?.let { activity.viewModelFactory.create(state, it) }
val args: SharedSecureStorageActivity.Args = activity.intent.getParcelableExtra(MvRx.KEY_ARG) ?: error("Missing args")
return activity.viewModelFactory.create(state, args)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class HomeActivityViewModel @AssistedInject constructor(
override fun create(viewModelContext: ViewModelContext, state: HomeActivityViewState): HomeActivityViewModel? {
val activity: HomeActivity = viewModelContext.activity()
val args: HomeActivityArgs? = activity.intent.getParcelableExtra(MvRx.KEY_ARG)
return args?.let { activity.viewModelFactory.create(state, it) }
return activity.viewModelFactory.create(state, args ?: HomeActivityArgs(clearNotification = false, accountCreation = false))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, size.width, size.height, ContentUrlResolver.ThumbnailMethod.SCALE)
}
// Fallback to base url
?: data.url
?: data.url.takeIf { it?.startsWith("content://") == true }

GlideApp
.with(imageView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
id("encryption")
enabled(enableFormElement)
title(stringProvider.getString(R.string.create_room_encryption_title))
summary(stringProvider.getString(R.string.create_room_encryption_description))
summary(
if (viewState.hsAdminHasDisabledE2E) stringProvider.getString(R.string.settings_hs_admin_e2e_disabled)
else stringProvider.getString(R.string.create_room_encryption_description)
)
switchChecked(viewState.isEncrypted)

listener { value ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
fun create(initialState: CreateRoomViewState): CreateRoomViewModel
}

init {
setState {
copy(
isEncrypted = !this.isPublic && session.getHomeServerCapabilities().adminE2EByDefault,
hsAdminHasDisabledE2E = !session.getHomeServerCapabilities().adminE2EByDefault
)
}
}

companion object : MvRxViewModelFactory<CreateRoomViewModel, CreateRoomViewState> {

@JvmStatic
Expand All @@ -69,7 +78,12 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr

private fun setName(action: CreateRoomAction.SetName) = setState { copy(roomName = action.name) }

private fun setIsPublic(action: CreateRoomAction.SetIsPublic) = setState { copy(isPublic = action.isPublic) }
private fun setIsPublic(action: CreateRoomAction.SetIsPublic) = setState {
copy(
isPublic = action.isPublic,
isEncrypted = !action.isPublic && session.getHomeServerCapabilities().adminE2EByDefault
)
}

private fun setIsInRoomDirectory(action: CreateRoomAction.SetIsInRoomDirectory) = setState { copy(isInRoomDirectory = action.isInRoomDirectory) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ data class CreateRoomViewState(
val isPublic: Boolean = false,
val isInRoomDirectory: Boolean = false,
val isEncrypted: Boolean = false,
val hsAdminHasDisabledE2E: Boolean = false,
val asyncCreateRoomRequest: Async<String> = Uninitialized
) : MvRxState
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
const val SETTINGS_ALLOW_INTEGRATIONS_KEY = "SETTINGS_ALLOW_INTEGRATIONS_KEY"
const val SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY = "SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY"
const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY"

const val SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT = "SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT"
// const val SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY = "SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY"

// user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package im.vector.riotx.features.settings
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
Expand All @@ -28,6 +31,7 @@ import androidx.core.view.isVisible
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.SwitchPreference
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.internal.crypto.crosssigning.isVerified
Expand Down Expand Up @@ -55,6 +59,7 @@ import im.vector.riotx.features.crypto.recover.BootstrapBottomSheet
import im.vector.riotx.features.themes.ThemeUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import me.gujun.android.span.span
import javax.inject.Inject

class VectorSettingsSecurityPrivacyFragment @Inject constructor(
Expand Down Expand Up @@ -96,6 +101,15 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY)!!
}

override fun onCreateRecyclerView(inflater: LayoutInflater?, parent: ViewGroup?, savedInstanceState: Bundle?): RecyclerView {
return super.onCreateRecyclerView(inflater, parent, savedInstanceState).also {
// Insert animation are really annoying the first time the list is shown
// due to the way preference fragment is done, it's not trivial to disable it for first appearance only..
// And it's not that an issue that this list is not animated, it's pretty static
it.itemAnimator = null
}
}

override fun onResume() {
super.onResume()
// My device name may have been updated
Expand All @@ -109,6 +123,9 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
}.also {
disposables.add(it)
}

val e2eByDefault = session.getHomeServerCapabilities().adminE2EByDefault
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT)?.isVisible = !e2eByDefault
}

private val secureBackupCategory by lazy {
Expand Down Expand Up @@ -220,6 +237,19 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
ThemeUtils.tintDrawable(it,
ContextCompat.getDrawable(it, R.drawable.ic_secure_backup)!!, R.attr.vctr_settings_icon_tint_color)
}

findPreference<VectorPreference>(VectorPreferences.SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT)?.let {
it.icon = ThemeUtils.tintDrawableWithColor(
ContextCompat.getDrawable(requireContext(), R.drawable.ic_notification_privacy_warning)!!,
ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
)
it.summary = span {
text = getString(R.string.settings_hs_admin_e2e_disabled)
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}

it.isVisible = session.getHomeServerCapabilities().adminE2EByDefault
}
}

// Todo this should be refactored and use same state as 4S section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.view.MenuItem
import android.view.View
import android.widget.ScrollView
import androidx.core.view.forEach
import androidx.core.view.isVisible
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.args
import com.airbnb.mvrx.withState
Expand All @@ -35,6 +36,8 @@ import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.setupAsSearch
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.utils.DimensionConverter
import im.vector.riotx.features.createdirect.CreateDirectRoomViewModel
import im.vector.riotx.features.createdirect.CreateDirectRoomViewState
import kotlinx.android.synthetic.main.fragment_known_users.*
import javax.inject.Inject

Expand All @@ -51,20 +54,26 @@ class KnownUsersFragment @Inject constructor(
override fun getMenuRes() = args.menuResId

private val viewModel: UserDirectoryViewModel by activityViewModel()
private val createDMViewModel: CreateDirectRoomViewModel by activityViewModel()

private lateinit var sharedActionViewModel: UserDirectorySharedActionViewModel

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
sharedActionViewModel = activityViewModelProvider.get(UserDirectorySharedActionViewModel::class.java)

knownUsersTitle.text = args.title

vectorBaseActivity.setSupportActionBar(knownUsersToolbar)
setupRecyclerView()
setupFilterView()
setupAddByMatrixIdView()
setupAddFromPhoneBookView()
setupCloseView()

createDMViewModel.selectSubscribe(this, CreateDirectRoomViewState::hsAdminHasDisabledE2E) {
knownUsersE2EbyDefaultDisabled.isVisible = it
}

viewModel.selectSubscribe(this, UserDirectoryViewState::pendingInvitees) {
renderSelectedUsers(it)
}
Expand Down
17 changes: 16 additions & 1 deletion vector/src/main/res/layout/fragment_known_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/knownUsersFilter" />


<TextView
android:id="@+id/knownUsersE2EbyDefaultDisabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:drawablePadding="8dp"
android:text="@string/settings_hs_admin_e2e_disabled"
android:textColor="?riotx_text_secondary"
android:textSize="14sp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/knownUsersFilterDivider"
tools:visibility="visible" />


<com.google.android.material.button.MaterialButton
android:id="@+id/addByMatrixId"
style="@style/VectorButtonStyleText"
Expand All @@ -121,7 +136,7 @@
app:iconPadding="13dp"
app:iconTint="@color/riotx_accent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/knownUsersFilterDivider" />
app:layout_constraintTop_toBottomOf="@id/knownUsersE2EbyDefaultDisabled" />

<com.google.android.material.button.MaterialButton
android:id="@+id/addFromPhoneBook"
Expand Down
Loading

0 comments on commit 7fddfa4

Please sign in to comment.