Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.9.33'
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Feb 10, 2020
2 parents 43a9817 + 0ae87e2 commit c1a911a
Show file tree
Hide file tree
Showing 49 changed files with 1,606 additions and 2,293 deletions.
16 changes: 15 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Changes to Matrix Android SDK in 0.9.33 (2020-02-10)
=======================================================

Features:
- HTTP Proxy configuration using HomeServerConnectionConfig

Bugfix:
- Fix bad constant values for homeserver CS api versions
- Ensure custom fields are sent for `m.room.message` Events (#515)
- Fix issue of blocked UI after a video call (#496, vector-im/riot-android#3311)

Others:
- Cleanup in org.matrix.androisdk.call

Changes to Matrix Android SDK in 0.9.32 (2019-11-25)
=======================================================

Expand Down Expand Up @@ -1628,7 +1642,7 @@ Features:
=======================================================


Changes to Matrix Android SDK in 0.9.X (2019-XX-XX)
Changes to Matrix Android SDK in 0.9.X (2020-XX-XX)
=======================================================

Features:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package org.matrix.androidsdk;

import android.net.Uri;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -29,6 +30,8 @@
import org.matrix.androidsdk.rest.model.login.Credentials;
import org.matrix.androidsdk.ssl.Fingerprint;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -61,6 +64,11 @@ public class HomeServerConnectionConfig {
private boolean mShouldAcceptTlsExtensions = true;
// Force usage of TLS versions
private boolean mForceUsageTlsVersions;
// the proxy hostname
private String mProxyHostname;
// the proxy port
private int mProxyPort = -1;


/**
* Private constructor. Please use the Builder
Expand Down Expand Up @@ -160,7 +168,7 @@ public void setCredentials(Credentials credentials) {

/**
* @return whether we should reject X509 certs that were issued by trusts CAs and only trust
* certs with matching fingerprints.
* certs with matching fingerprints.
*/
public boolean shouldPin() {
return mPin;
Expand Down Expand Up @@ -196,6 +204,21 @@ public boolean forceUsageOfTlsVersions() {
return mForceUsageTlsVersions;
}


/**
* @return proxy config if available
*/
@Nullable
public Proxy getProxyConfig() {
if (mProxyHostname == null || mProxyHostname.length() == 0 || mProxyPort == -1) {
return null;
}

return new Proxy(Proxy.Type.HTTP,
new InetSocketAddress(mProxyHostname, mProxyPort));
}


@Override
public String toString() {
return "HomeserverConnectionConfig{" +
Expand All @@ -206,6 +229,8 @@ public String toString() {
", mCredentials=" + mCredentials +
", mPin=" + mPin +
", mShouldAcceptTlsExtensions=" + mShouldAcceptTlsExtensions +
", mProxyHostname=" + (null == mProxyHostname ? "" : mProxyHostname) +
", mProxyPort=" + (-1 == mProxyPort ? "" : mProxyPort) +
", mTlsVersions=" + (null == mTlsVersions ? "" : mTlsVersions.size()) +
", mTlsCipherSuites=" + (null == mTlsCipherSuites ? "" : mTlsCipherSuites.size()) +
'}';
Expand Down Expand Up @@ -267,6 +292,14 @@ public JSONObject toJson() throws JSONException {
json.put("tls_cipher_suites", new JSONArray(tlsCipherSuites));
}

if (mProxyPort != -1) {
json.put("proxy_port", mProxyPort);
}

if (mProxyHostname != null && mProxyHostname.length() > 0) {
json.put("proxy_hostname", mProxyHostname);
}

return json;
}

Expand Down Expand Up @@ -323,6 +356,11 @@ public static HomeServerConnectionConfig fromJson(JSONObject jsonObject) throws
}
}

// Set the proxy options right if any
if (jsonObject.has("proxy_hostname") && jsonObject.has("proxy_port")) {
builder.withProxy(jsonObject.getString("proxy_hostname"), jsonObject.getInt("proxy_port"));
}

return builder.build();
}

Expand Down Expand Up @@ -549,6 +587,17 @@ public Builder withTlsLimitations(boolean tlsLimitations, boolean enableCompatib
return this;
}

/**
* @param proxyHostname Proxy Hostname
* @param proxyPort Proxy Port
* @return this builder
*/
public Builder withProxy(@Nullable String proxyHostname, int proxyPort) {
mHomeServerConnectionConfig.mProxyHostname = proxyHostname;
mHomeServerConnectionConfig.mProxyPort = proxyPort;
return this;
}

/**
* @return the {@link HomeServerConnectionConfig}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RestClientHttpClientFactory(private val testInterceptor: Interceptor? = nu
.connectTimeout(RestClient.CONNECTION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
.readTimeout(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.writeTimeout(WRITE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
.proxy(hsConfig.proxyConfig)
.addInterceptor(authenticationInterceptor)

if (BuildConfig.DEBUG) {
Expand Down
4 changes: 2 additions & 2 deletions matrix-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 932
versionName "0.9.32"
versionCode 933
versionName "0.9.33"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// Enable multi dex for test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2020 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 org.matrix.androidsdk.event

import android.text.TextUtils
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import com.google.gson.JsonParser
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.matrix.androidsdk.common.CommonTestHelper
import org.matrix.androidsdk.common.CryptoTestHelper
import org.matrix.androidsdk.common.TestApiCallback
import org.matrix.androidsdk.common.TestConstants
import org.matrix.androidsdk.core.Log
import org.matrix.androidsdk.data.RoomState
import org.matrix.androidsdk.listeners.MXEventListener
import org.matrix.androidsdk.rest.model.Event
import java.util.concurrent.CountDownLatch

@RunWith(AndroidJUnit4::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class SendCustomEventTest {
private val mTestHelper = CommonTestHelper()
private val mCryptoTestHelper = CryptoTestHelper(mTestHelper)

@Test
fun test01_sendCustomEvent() {
Log.e(LOG_TAG, "test01_sendEvent")
val context = InstrumentationRegistry.getContext()
val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, mCryptoTestHelper.defaultSessionParams)
var roomId: String? = null
val lock1 = CountDownLatch(1)
bobSession.createRoom(object : TestApiCallback<String>(lock1) {
override fun onSuccess(info: String) {
roomId = info
super.onSuccess(info)
}
})
mTestHelper.await(lock1)
assertNotNull(roomId)
val room = bobSession.dataHandler.getRoom(roomId!!)
// Wait for the event
var receivedEvent: Event? = null
val lock3 = CountDownLatch(1)
bobSession.dataHandler.addListener(object : MXEventListener() {
override fun onLiveEvent(event: Event, roomState: RoomState) {
if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
receivedEvent = event
lock3.countDown()
}
}
})
// Send event
val parser = JsonParser()
val element = parser.parse("{" +
"\"body\" : \"message body\"," +
"\"msgtype\" : \"m.text\"," +
"\"mirrorIdKey\" : \"customValue\"" +
"}")
val content = element.asJsonObject
val event = Event(Event.EVENT_TYPE_MESSAGE, content, bobSession.myUserId, roomId)
val lock2 = CountDownLatch(1)
room.sendEvent(event, TestApiCallback(lock2))
mTestHelper.await(lock2)
// Wait for the callback
mTestHelper.await(lock3)

assertNotNull(receivedEvent)
assertEquals("message body", receivedEvent!!.content.asJsonObject.get("body")?.asString)
assertEquals("m.text", receivedEvent!!.content.asJsonObject.get("msgtype")?.asString)
assertEquals("customValue", receivedEvent!!.content.asJsonObject.get("mirrorIdKey")?.asString)

bobSession.clear(context)
}

companion object {
private const val LOG_TAG = "EventTest"
}
}
91 changes: 0 additions & 91 deletions matrix-sdk/src/main/assets/www/androidcall.js

This file was deleted.

Loading

0 comments on commit c1a911a

Please sign in to comment.