Upgrade to matrix-android-sdk 0.9.14.

There's a bunch of changes, required, to move to the latest SDK:

1. Update AAR's.  The matrix-sdk.aar in this commit was built from the
v0.9.14 tag of the matrix-android-sdk git repository.  olm-sdk.jar is
pulled from the same place.

2. Updates to the build scripts.  matrix-android-sdk added kotlin as a
dependency, moved to okhttp3, added io.realm, and so on.

3. Code modifications to support new SDK itself.  The changes, here, are
a grab bag, and you're best off just reading the commit.

Of particular note, here, is that LoginRestClient.loginWithUser takes a
device name *and* a device ID, now (the previous API only took a device
name).  As a wicked had, right now, I'm just using the name as the ID,
but I have no doubt that's wrong and this should be cleaned up to
include a randomly generated, persisted device ID, as I believe this is
used by Synapse to track login sessions.
pull/41/head
Brett Kosinski 5 years ago
parent 6fab08d956
commit 575f591c13

@ -1,12 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "eu.droogers.smsmatrix"
minSdkVersion 23
targetSdkVersion 26
targetSdkVersion 27
versionCode 10
versionName "0.0.10"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@ -23,23 +26,32 @@ android {
dir 'libs'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:26.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testCompile 'junit:junit:4.12'
compile(name: 'matrix-sdk', ext: 'aar')
compile(name: 'olm-sdk', ext: 'aar')
implementation(name: 'matrix-sdk', ext: 'aar')
implementation(name: 'olm-sdk', ext: 'aar')
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
}

Binary file not shown.

Binary file not shown.

@ -6,6 +6,7 @@ import org.matrix.androidsdk.data.MyUser;
import org.matrix.androidsdk.data.RoomState;
import org.matrix.androidsdk.listeners.IMXEventListener;
import org.matrix.androidsdk.rest.model.Event;
import org.matrix.androidsdk.rest.model.MatrixError;
import org.matrix.androidsdk.rest.model.User;
import org.matrix.androidsdk.rest.model.bingrules.BingRule;
@ -69,7 +70,7 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onEventEncrypted(Event event) {
public void onEventSentStateUpdated(Event event) {
}
@ -83,11 +84,6 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onFailedSendingEvent(Event event) {
}
@Override
public void onBingRulesUpdate() {
@ -100,6 +96,11 @@ public class EventListener implements IMXEventListener {
mx.getUnreadEvents();
}
@Override
public void onSyncError(MatrixError matrixError) {
}
@Override
public void onCryptoSyncComplete() {
@ -121,12 +122,12 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onRoomInitialSyncComplete(String s) {
public void onRoomInternalUpdate(String s) {
}
@Override
public void onRoomInternalUpdate(String s) {
public void onNotificationCountUpdate(String s) {
}
@ -135,6 +136,11 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onRoomKick(String s) {
}
@Override
public void onReceiptEvent(String s, List<String> list) {
@ -154,4 +160,44 @@ public class EventListener implements IMXEventListener {
public void onToDeviceEvent(Event event) {
}
@Override
public void onNewGroupInvitation(String s) {
}
@Override
public void onJoinGroup(String s) {
}
@Override
public void onLeaveGroup(String s) {
}
@Override
public void onGroupProfileUpdate(String s) {
}
@Override
public void onGroupRoomsListUpdate(String s) {
}
@Override
public void onGroupUsersListUpdate(String s) {
}
@Override
public void onGroupInvitedUsersListUpdate(String s) {
}
@Override
public void onAccountDataUpdated() {
}
}

@ -27,8 +27,9 @@ import org.matrix.androidsdk.listeners.IMXEventListener;
import org.matrix.androidsdk.listeners.MXMediaUploadListener;
import org.matrix.androidsdk.rest.callback.SimpleApiCallback;
import org.matrix.androidsdk.rest.client.LoginRestClient;
import org.matrix.androidsdk.rest.model.CreatedEvent;
import org.matrix.androidsdk.rest.model.Event;
import org.matrix.androidsdk.rest.model.Message;
import org.matrix.androidsdk.rest.model.message.Message;
import org.matrix.androidsdk.rest.model.login.Credentials;
import java.io.ByteArrayInputStream;
@ -70,7 +71,10 @@ public class Matrix {
public Matrix(final Context context, String url, String botUsername, String botPassword, String username, String device, String syncDelay, String syncTimeout) {
this.context = context;
hsConfig = new HomeServerConnectionConfig(Uri.parse(url));
HomeServerConnectionConfig.Builder builder = new HomeServerConnectionConfig.Builder();
hsConfig = builder.withHomeServerUri(Uri.parse(url)).build();
realUserid = username;
deviceName = device;
@ -83,11 +87,10 @@ public class Matrix {
}
private void login(String username, String password) {
new LoginRestClient(hsConfig).loginWithUser(username, password, deviceName, new SimpleApiCallback<Credentials>() {
new LoginRestClient(hsConfig).loginWithUser(username, password, deviceName, deviceName, new SimpleApiCallback<Credentials>() {
@Override
public void onSuccess(Credentials credentials) {
super.onSuccess(credentials);
onLogin(credentials);
}
});
@ -103,7 +106,7 @@ public class Matrix {
if (false) {
store = new MXFileStore(hsConfig, context);
store = new MXFileStore(hsConfig, false, context);
} else {
store = new MXMemoryStore(hsConfig.getCredentials(), context);
}
@ -112,7 +115,9 @@ public class Matrix {
// NetworkConnectivityReceiver nwMan = new NetworkConnectivityReceiver();
session = new MXSession(hsConfig, dh, context);
MXSession.Builder builder = new MXSession.Builder(hsConfig, dh, context);
session = builder.build();
session.setSyncDelay(syncDelay * 1000);
session.setSyncTimeout(syncTimeout * 60 * 1000);
Log.e(TAG, "onLogin:" + session.getSyncTimeout());
@ -120,7 +125,6 @@ public class Matrix {
if (store.isReady()) {
session.getDataHandler().checkPermanentStorageData();
session.startEventStream(store.getEventStreamToken());
session.getDataHandler().addListener(evLis);
} else {
@ -132,7 +136,6 @@ public class Matrix {
@Override
public void onStoreReady(String s) {
session.getDataHandler().checkPermanentStorageData();
session.startEventStream(store.getEventStreamToken());
session.getDataHandler().addListener(evLis);
}
@ -161,11 +164,16 @@ public class Matrix {
if (room == null) {
if (!type.equals("m.notice")) {
Log.e(TAG, "sendMessage: not found" );
session.createRoomDirectMessage(realUserid, new SimpleApiCallback<String>() {
session.createDirectMessageRoom(realUserid, new SimpleApiCallback<String>() {
@Override
public void onSuccess(String info) {
super.onSuccess(info);
session.getRoomsApiClient().updateTopic(info, phoneNumber, new SimpleApiCallback<Void>());
session.getRoomsApiClient().updateTopic(info, phoneNumber, new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
changeDisplayname(info, getContactName(phoneNumber, context));
Room room = store.getRoom(info);
SendMesageToRoom(room, body, type);
@ -191,7 +199,7 @@ public class Matrix {
) {
String uploadID = String.valueOf(transaction);
transaction++;
session.getMediasCache().uploadContent(
session.getMediaCache().uploadContent(
new ByteArrayInputStream(body),
fileName,
contentType,
@ -213,7 +221,12 @@ public class Matrix {
room.getRoomId(),
"m.room.message",
json,
new SimpleApiCallback<Event>()
new SimpleApiCallback<CreatedEvent>() {
@Override
public void onSuccess(CreatedEvent createdEvent) {
}
}
);
transaction++;
}
@ -225,14 +238,24 @@ public class Matrix {
Map<String, Object> params = new HashMap<>();
params.put("displayname", displayname);
params.put("membership", "join");
session.getRoomsApiClient().sendStateEvent(roomId, "m.room.member", session.getMyUserId(), params, new SimpleApiCallback<Void>());
session.getRoomsApiClient().sendStateEvent(roomId, "m.room.member", session.getMyUserId(), params, new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
}
public void SendMesageToRoom(Room room, String body, String type) {
Message msg = new Message();
msg.body = body;
msg.msgtype = type;
session.getRoomsApiClient().sendMessage(String.valueOf(transaction), room.getRoomId(), msg, new SimpleApiCallback<Event>());
session.getRoomsApiClient().sendMessage(String.valueOf(transaction), room.getRoomId(), msg, new SimpleApiCallback<CreatedEvent>() {
@Override
public void onSuccess(CreatedEvent createdEvent) {
}
});
transaction++;
}
@ -250,7 +273,7 @@ public class Matrix {
}
public void sendEvent(Event event) {
if (event.sender.equals(realUserid)) {
if ((event.sender != null) && (event.sender.equals(realUserid))) {
Room room = store.getRoom(event.roomId);
SmsManager smsManager = SmsManager.getDefault();
JsonObject json = event.getContent().getAsJsonObject();
@ -265,16 +288,31 @@ public class Matrix {
}
} else if (event.type.equals("m.room.member")) {
if (json.get("membership").getAsString().equals("leave")) {
room.leave(new SimpleApiCallback<Void>());
room.leave(new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
} else if (json.get("membership").getAsString().equals("invite")) {
room.join(new SimpleApiCallback<Void>());
room.join(new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
}
} else {
Log.e(TAG, "sendEvent: Event type not supported ");
}
room.markAllAsRead(new SimpleApiCallback<Void>());
room.markAllAsRead(new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
}
}

@ -1,12 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "io.realm:realm-gradle-plugin:5.8.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

Loading…
Cancel
Save