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

Commit c1a911a

Browse files
committed
Merge branch 'release/0.9.33'
2 parents 43a9817 + 0ae87e2 commit c1a911a

File tree

49 files changed

+1606
-2293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1606
-2293
lines changed

CHANGES.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Changes to Matrix Android SDK in 0.9.33 (2020-02-10)
2+
=======================================================
3+
4+
Features:
5+
- HTTP Proxy configuration using HomeServerConnectionConfig
6+
7+
Bugfix:
8+
- Fix bad constant values for homeserver CS api versions
9+
- Ensure custom fields are sent for `m.room.message` Events (#515)
10+
- Fix issue of blocked UI after a video call (#496, vector-im/riot-android#3311)
11+
12+
Others:
13+
- Cleanup in org.matrix.androisdk.call
14+
115
Changes to Matrix Android SDK in 0.9.32 (2019-11-25)
216
=======================================================
317

@@ -1628,7 +1642,7 @@ Features:
16281642
=======================================================
16291643

16301644

1631-
Changes to Matrix Android SDK in 0.9.X (2019-XX-XX)
1645+
Changes to Matrix Android SDK in 0.9.X (2020-XX-XX)
16321646
=======================================================
16331647

16341648
Features:

matrix-sdk-core/src/main/java/org/matrix/androidsdk/HomeServerConnectionConfig.java

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package org.matrix.androidsdk;
1919

2020
import android.net.Uri;
21+
import android.text.TextUtils;
22+
2123
import androidx.annotation.NonNull;
2224
import androidx.annotation.Nullable;
23-
import android.text.TextUtils;
2425

2526
import org.json.JSONArray;
2627
import org.json.JSONException;
@@ -29,6 +30,8 @@
2930
import org.matrix.androidsdk.rest.model.login.Credentials;
3031
import org.matrix.androidsdk.ssl.Fingerprint;
3132

33+
import java.net.InetSocketAddress;
34+
import java.net.Proxy;
3235
import java.util.ArrayList;
3336
import java.util.List;
3437

@@ -61,6 +64,11 @@ public class HomeServerConnectionConfig {
6164
private boolean mShouldAcceptTlsExtensions = true;
6265
// Force usage of TLS versions
6366
private boolean mForceUsageTlsVersions;
67+
// the proxy hostname
68+
private String mProxyHostname;
69+
// the proxy port
70+
private int mProxyPort = -1;
71+
6472

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

161169
/**
162170
* @return whether we should reject X509 certs that were issued by trusts CAs and only trust
163-
* certs with matching fingerprints.
171+
* certs with matching fingerprints.
164172
*/
165173
public boolean shouldPin() {
166174
return mPin;
@@ -196,6 +204,21 @@ public boolean forceUsageOfTlsVersions() {
196204
return mForceUsageTlsVersions;
197205
}
198206

207+
208+
/**
209+
* @return proxy config if available
210+
*/
211+
@Nullable
212+
public Proxy getProxyConfig() {
213+
if (mProxyHostname == null || mProxyHostname.length() == 0 || mProxyPort == -1) {
214+
return null;
215+
}
216+
217+
return new Proxy(Proxy.Type.HTTP,
218+
new InetSocketAddress(mProxyHostname, mProxyPort));
219+
}
220+
221+
199222
@Override
200223
public String toString() {
201224
return "HomeserverConnectionConfig{" +
@@ -206,6 +229,8 @@ public String toString() {
206229
", mCredentials=" + mCredentials +
207230
", mPin=" + mPin +
208231
", mShouldAcceptTlsExtensions=" + mShouldAcceptTlsExtensions +
232+
", mProxyHostname=" + (null == mProxyHostname ? "" : mProxyHostname) +
233+
", mProxyPort=" + (-1 == mProxyPort ? "" : mProxyPort) +
209234
", mTlsVersions=" + (null == mTlsVersions ? "" : mTlsVersions.size()) +
210235
", mTlsCipherSuites=" + (null == mTlsCipherSuites ? "" : mTlsCipherSuites.size()) +
211236
'}';
@@ -267,6 +292,14 @@ public JSONObject toJson() throws JSONException {
267292
json.put("tls_cipher_suites", new JSONArray(tlsCipherSuites));
268293
}
269294

295+
if (mProxyPort != -1) {
296+
json.put("proxy_port", mProxyPort);
297+
}
298+
299+
if (mProxyHostname != null && mProxyHostname.length() > 0) {
300+
json.put("proxy_hostname", mProxyHostname);
301+
}
302+
270303
return json;
271304
}
272305

@@ -323,6 +356,11 @@ public static HomeServerConnectionConfig fromJson(JSONObject jsonObject) throws
323356
}
324357
}
325358

359+
// Set the proxy options right if any
360+
if (jsonObject.has("proxy_hostname") && jsonObject.has("proxy_port")) {
361+
builder.withProxy(jsonObject.getString("proxy_hostname"), jsonObject.getInt("proxy_port"));
362+
}
363+
326364
return builder.build();
327365
}
328366

@@ -549,6 +587,17 @@ public Builder withTlsLimitations(boolean tlsLimitations, boolean enableCompatib
549587
return this;
550588
}
551589

590+
/**
591+
* @param proxyHostname Proxy Hostname
592+
* @param proxyPort Proxy Port
593+
* @return this builder
594+
*/
595+
public Builder withProxy(@Nullable String proxyHostname, int proxyPort) {
596+
mHomeServerConnectionConfig.mProxyHostname = proxyHostname;
597+
mHomeServerConnectionConfig.mProxyPort = proxyPort;
598+
return this;
599+
}
600+
552601
/**
553602
* @return the {@link HomeServerConnectionConfig}
554603
*/

matrix-sdk-core/src/main/java/org/matrix/androidsdk/RestClientHttpClientFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class RestClientHttpClientFactory(private val testInterceptor: Interceptor? = nu
4343
.connectTimeout(RestClient.CONNECTION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
4444
.readTimeout(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS)
4545
.writeTimeout(WRITE_TIMEOUT_MS, TimeUnit.MILLISECONDS)
46+
.proxy(hsConfig.proxyConfig)
4647
.addInterceptor(authenticationInterceptor)
4748

4849
if (BuildConfig.DEBUG) {

matrix-sdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ android {
2727
defaultConfig {
2828
minSdkVersion 16
2929
targetSdkVersion 28
30-
versionCode 932
31-
versionName "0.9.32"
30+
versionCode 933
31+
versionName "0.9.33"
3232
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3333

3434
// Enable multi dex for test
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright 2020 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.matrix.androidsdk.event
17+
18+
import android.text.TextUtils
19+
import androidx.test.InstrumentationRegistry
20+
import androidx.test.runner.AndroidJUnit4
21+
import com.google.gson.JsonParser
22+
import org.junit.Assert.assertEquals
23+
import org.junit.Assert.assertNotNull
24+
import org.junit.FixMethodOrder
25+
import org.junit.Test
26+
import org.junit.runner.RunWith
27+
import org.junit.runners.MethodSorters
28+
import org.matrix.androidsdk.common.CommonTestHelper
29+
import org.matrix.androidsdk.common.CryptoTestHelper
30+
import org.matrix.androidsdk.common.TestApiCallback
31+
import org.matrix.androidsdk.common.TestConstants
32+
import org.matrix.androidsdk.core.Log
33+
import org.matrix.androidsdk.data.RoomState
34+
import org.matrix.androidsdk.listeners.MXEventListener
35+
import org.matrix.androidsdk.rest.model.Event
36+
import java.util.concurrent.CountDownLatch
37+
38+
@RunWith(AndroidJUnit4::class)
39+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
40+
class SendCustomEventTest {
41+
private val mTestHelper = CommonTestHelper()
42+
private val mCryptoTestHelper = CryptoTestHelper(mTestHelper)
43+
44+
@Test
45+
fun test01_sendCustomEvent() {
46+
Log.e(LOG_TAG, "test01_sendEvent")
47+
val context = InstrumentationRegistry.getContext()
48+
val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, mCryptoTestHelper.defaultSessionParams)
49+
var roomId: String? = null
50+
val lock1 = CountDownLatch(1)
51+
bobSession.createRoom(object : TestApiCallback<String>(lock1) {
52+
override fun onSuccess(info: String) {
53+
roomId = info
54+
super.onSuccess(info)
55+
}
56+
})
57+
mTestHelper.await(lock1)
58+
assertNotNull(roomId)
59+
val room = bobSession.dataHandler.getRoom(roomId!!)
60+
// Wait for the event
61+
var receivedEvent: Event? = null
62+
val lock3 = CountDownLatch(1)
63+
bobSession.dataHandler.addListener(object : MXEventListener() {
64+
override fun onLiveEvent(event: Event, roomState: RoomState) {
65+
if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) {
66+
receivedEvent = event
67+
lock3.countDown()
68+
}
69+
}
70+
})
71+
// Send event
72+
val parser = JsonParser()
73+
val element = parser.parse("{" +
74+
"\"body\" : \"message body\"," +
75+
"\"msgtype\" : \"m.text\"," +
76+
"\"mirrorIdKey\" : \"customValue\"" +
77+
"}")
78+
val content = element.asJsonObject
79+
val event = Event(Event.EVENT_TYPE_MESSAGE, content, bobSession.myUserId, roomId)
80+
val lock2 = CountDownLatch(1)
81+
room.sendEvent(event, TestApiCallback(lock2))
82+
mTestHelper.await(lock2)
83+
// Wait for the callback
84+
mTestHelper.await(lock3)
85+
86+
assertNotNull(receivedEvent)
87+
assertEquals("message body", receivedEvent!!.content.asJsonObject.get("body")?.asString)
88+
assertEquals("m.text", receivedEvent!!.content.asJsonObject.get("msgtype")?.asString)
89+
assertEquals("customValue", receivedEvent!!.content.asJsonObject.get("mirrorIdKey")?.asString)
90+
91+
bobSession.clear(context)
92+
}
93+
94+
companion object {
95+
private const val LOG_TAG = "EventTest"
96+
}
97+
}

matrix-sdk/src/main/assets/www/androidcall.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)