1
0
mirror of https://github.com/tijder/SmsMatrix.git synced 2024-10-27 18:24:01 +00:00

Compare commits

..

No commits in common. "master" and "v0.0.11" have entirely different histories.

14 changed files with 66 additions and 235 deletions

View File

@ -1,28 +1,18 @@
<a href="https://matrix.to/#/#smsmatrix:matrix.org">
<img src="https://img.shields.io/badge/Chat-On%20Matrix-green"
alt="Chat on Matrix"/>
</a>
# SmsMatrix
A simple SMS (text message) &lt;--> Matrix bridge.
This app bridges all sms messages to matrix. For every (new) text conversation contact the bot will open a private 1:1 room and sends the incoming messages to that room. Any messages sent in that room by the matrix user will then be sent to the contact via SMS.
As currently there is no end-to-end encryption implemented in this app, for privacy reasons it is preferable to use it with your own Matrix server. Your data-in-transit however will always be safe as they are encrypted using https over matrix -- provided the Matrix server is configured properly.
<a href="https://f-droid.org/app/eu.droogers.smsmatrix">
<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
alt="Get it on F-Droid" height="80"/>
</a>
# Set up
- Create an account on a homeserver
- Install this app (apk can be found by [releases](https://github.com/tijder/SmsMatrix/releases) or from [f-droid](https://f-droid.org/app/eu.droogers.smsmatrix))
- Create a acount on a homeserver
- Install this app (apk can be found by [releases](https://github.com/tijder/SmsMatrix/releases))
- Give the app the app permission
- Type in the needed info in the app
- Bot Username: is the username of the just created user
- Bot Password: is the password of the just created user
- Homeserver url: is the url of the homeserver where the user is created
- Your username: is where you want to forward all your text messages to
- Your username: is where you want to forward all yous text message to
- Devicename: is the devicename wich the api will use
- Press save
- Now all your text messages will be bridged

View File

@ -1,18 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
compileSdkVersion 29
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "eu.droogers.smsmatrix"
minSdkVersion 23
targetSdkVersion 29
versionCode 16
versionName "0.0.16"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
targetSdkVersion 26
versionCode 11
versionName "0.0.11"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
@ -26,33 +23,23 @@ android {
dir 'libs'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
implementation 'com.android.support:appcompat-v7:26.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
/************* Matrix SDK management **************/
implementation 'com.github.Bubu:matrix-android-sdk:v0.9.30-no-webrtc'
compile(name: 'matrix-sdk', ext: 'aar')
compile(name: 'olm-sdk', ext: 'aar')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.12.3'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.3'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
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'
}

BIN
app/libs/matrix-sdk.aar Normal file

Binary file not shown.

BIN
app/libs/olm-sdk.aar Normal file

Binary file not shown.

View File

@ -1,8 +1,8 @@
package eu.droogers.smsmatrix;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -7,8 +7,6 @@
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
tools:replace="allowBackup,label"
@ -33,9 +31,6 @@
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service android:name="eu.droogers.smsmatrix.MatrixService" />

View File

@ -6,10 +6,8 @@ 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.core.model.MatrixError;
import org.matrix.androidsdk.rest.model.User;
import org.matrix.androidsdk.rest.model.bingrules.BingRule;
import org.matrix.androidsdk.rest.model.sync.AccountDataElement;
import java.util.List;
@ -53,7 +51,7 @@ public class EventListener implements IMXEventListener {
@Override
public void onLiveEvent(Event event, RoomState roomState) {
if (loaded) {
if (loaded == true) {
// mx.getUnreadEvents();
mx.sendEvent(event);
}
@ -71,7 +69,12 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onEventSentStateUpdated(Event event) {
public void onEventEncrypted(Event event) {
}
@Override
public void onEventDecrypted(Event event) {
}
@ -81,7 +84,7 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onEventDecrypted(String s, String s1) {
public void onFailedSendingEvent(Event event) {
}
@ -97,11 +100,6 @@ public class EventListener implements IMXEventListener {
mx.getUnreadEvents();
}
@Override
public void onSyncError(MatrixError matrixError) {
}
@Override
public void onCryptoSyncComplete() {
@ -122,26 +120,21 @@ public class EventListener implements IMXEventListener {
}
@Override
public void onRoomInitialSyncComplete(String s) {
}
@Override
public void onRoomInternalUpdate(String s) {
}
@Override
public void onNotificationCountUpdate(String s) {
}
@Override
public void onLeaveRoom(String s) {
}
@Override
public void onRoomKick(String s) {
}
@Override
public void onReceiptEvent(String s, List<String> list) {
@ -161,44 +154,4 @@ 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(AccountDataElement accountDataElement) {
}
}

View File

@ -1,5 +1,6 @@
package eu.droogers.smsmatrix;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@ -11,8 +12,8 @@ import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import static android.Manifest.permission.READ_CONTACTS;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;

View File

@ -25,12 +25,11 @@ import org.matrix.androidsdk.data.store.MXFileStore;
import org.matrix.androidsdk.data.store.MXMemoryStore;
import org.matrix.androidsdk.listeners.IMXEventListener;
import org.matrix.androidsdk.listeners.MXMediaUploadListener;
import org.matrix.androidsdk.core.callback.SimpleApiCallback;
import org.matrix.androidsdk.core.model.MatrixError;
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.Message;
import org.matrix.androidsdk.rest.model.MatrixError;
import org.matrix.androidsdk.rest.model.Message;
import org.matrix.androidsdk.rest.model.login.Credentials;
import java.io.ByteArrayInputStream;
@ -72,10 +71,7 @@ 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;
HomeServerConnectionConfig.Builder builder = new HomeServerConnectionConfig.Builder();
hsConfig = builder.withHomeServerUri(Uri.parse(url)).build();
hsConfig = new HomeServerConnectionConfig(Uri.parse(url));
realUserid = username;
deviceName = device;
@ -88,10 +84,11 @@ public class Matrix {
}
private void login(String username, String password) {
new LoginRestClient(hsConfig).loginWithUser(username, password, deviceName, deviceName, new SimpleApiCallback<Credentials>() {
new LoginRestClient(hsConfig).loginWithUser(username, password, deviceName, new SimpleApiCallback<Credentials>() {
@Override
public void onSuccess(Credentials credentials) {
super.onSuccess(credentials);
onLogin(credentials);
}
@ -122,7 +119,7 @@ public class Matrix {
if (false) {
store = new MXFileStore(hsConfig, false, context);
store = new MXFileStore(hsConfig, context);
} else {
store = new MXMemoryStore(hsConfig.getCredentials(), context);
}
@ -131,9 +128,7 @@ public class Matrix {
// NetworkConnectivityReceiver nwMan = new NetworkConnectivityReceiver();
MXSession.Builder builder = new MXSession.Builder(hsConfig, dh, context);
session = builder.build();
session = new MXSession(hsConfig, dh, context);
session.setSyncDelay(syncDelay * 1000);
session.setSyncTimeout(syncTimeout * 60 * 1000);
Log.e(TAG, "onLogin:" + session.getSyncTimeout());
@ -141,6 +136,7 @@ public class Matrix {
if (store.isReady()) {
session.getDataHandler().checkPermanentStorageData();
session.startEventStream(store.getEventStreamToken());
session.getDataHandler().addListener(evLis);
} else {
@ -152,6 +148,7 @@ public class Matrix {
@Override
public void onStoreReady(String s) {
session.getDataHandler().checkPermanentStorageData();
session.startEventStream(store.getEventStreamToken());
session.getDataHandler().addListener(evLis);
}
@ -180,16 +177,11 @@ public class Matrix {
if (room == null) {
if (!type.equals("m.notice")) {
Log.e(TAG, "sendMessage: not found" );
session.createDirectMessageRoom(realUserid, new SimpleApiCallback<String>() {
session.createRoomDirectMessage(realUserid, new SimpleApiCallback<String>() {
@Override
public void onSuccess(String info) {
session.getRoomsApiClient().updateTopic(info, phoneNumber, new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
super.onSuccess(info);
session.getRoomsApiClient().updateTopic(info, phoneNumber, new SimpleApiCallback<Void>());
changeDisplayname(info, getContactName(phoneNumber, context));
Room room = store.getRoom(info);
SendMesageToRoom(room, body, type);
@ -215,7 +207,7 @@ public class Matrix {
) {
String uploadID = String.valueOf(transaction);
transaction++;
session.getMediaCache().uploadContent(
session.getMediasCache().uploadContent(
new ByteArrayInputStream(body),
fileName,
contentType,
@ -237,12 +229,7 @@ public class Matrix {
room.getRoomId(),
"m.room.message",
json,
new SimpleApiCallback<CreatedEvent>() {
@Override
public void onSuccess(CreatedEvent createdEvent) {
}
}
new SimpleApiCallback<Event>()
);
transaction++;
}
@ -254,22 +241,17 @@ 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>() {
@Override
public void onSuccess(Void aVoid) {
}
});
session.getRoomsApiClient().sendStateEvent(roomId, "m.room.member", session.getMyUserId(), params, new SimpleApiCallback<Void>());
}
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<CreatedEvent>() {
session.getRoomsApiClient().sendMessage(String.valueOf(transaction), room.getRoomId(), msg, new SimpleApiCallback<Event>() {
@Override
public void onSuccess(CreatedEvent createdEvent) {
Log.e(TAG, "sendMessage success");
public void onSuccess(Event event) {
Log.i(TAG, "sendMessage success");
}
@Override
public void onMatrixError(MatrixError e) {
@ -301,7 +283,7 @@ public class Matrix {
}
public void sendEvent(Event event) {
if ((event.sender != null) && (event.sender.equals(realUserid))) {
if (event.sender.equals(realUserid)) {
Room room = store.getRoom(event.roomId);
SmsManager smsManager = SmsManager.getDefault();
JsonObject json = event.getContent().getAsJsonObject();
@ -316,31 +298,16 @@ public class Matrix {
}
} else if (event.type.equals("m.room.member")) {
if (json.get("membership").getAsString().equals("leave")) {
room.leave(new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
room.leave(new SimpleApiCallback<Void>());
} else if (json.get("membership").getAsString().equals("invite")) {
room.join(new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
room.join(new SimpleApiCallback<Void>());
}
} else {
Log.e(TAG, "sendEvent: Event type not supported ");
}
room.markAllAsRead(new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
room.markAllAsRead(new SimpleApiCallback<Void>());
}
}

View File

@ -1,22 +1,14 @@
package eu.droogers.smsmatrix;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
/**
* Created by gerben on 7-10-17.
*/
@ -32,7 +24,6 @@ public class MatrixService extends Service {
private String syncDelay;
private String syncTimeout;
private MMSMonitor mms;
private String mChannelId = "";
@Override
public void onCreate() {
@ -41,21 +32,6 @@ public class MatrixService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
if (mChannelId.isEmpty()) {
mChannelId = createNotificationChannel("sync", "Sync Service");
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, mChannelId);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(getApplicationInfo().loadLabel(getPackageManager()))
.setPriority(NotificationCompat.PRIORITY_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.build();
startForeground(1, notification);
}
SharedPreferences sp = getSharedPreferences("settings", Context.MODE_PRIVATE);
botUsername = sp.getString("botUsername", "");
botPassword = sp.getString("botPassword", "");
@ -100,22 +76,9 @@ public class MatrixService extends Service {
}
@RequiresApi(api = Build.VERSION_CODES.O)
private String createNotificationChannel(String channelId, String channelName){
NotificationChannel chan = new NotificationChannel(channelId,
channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager service = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
service.createNotificationChannel(chan);
return channelId;
}
@Override
public void onDestroy() {
if (mx != null) {
mx.destroy();
}
mx.destroy();
this.mms.stopMMSMonitoring();
this.mms = null;
super.onDestroy();

View File

@ -6,9 +6,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import androidx.core.content.ContextCompat;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
@ -26,10 +24,6 @@ public class ReceiverListener extends BroadcastReceiver {
} else if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
handleIncomingCall(context, intent);
}
else if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent intentServ = new Intent(context, MatrixService.class);
ContextCompat.startForegroundService(context, intentServ);
}
}
private void handleIncomingSMS(Context context, Intent intent) {

View File

@ -1,16 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:5.8.0"
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@ -19,19 +15,6 @@ buildscript {
allprojects {
repositories {
// For Matrix Android SDK.
// This has to be declared first, to ensure that Matrix Android SDK library is not downloaded from another repo
maven {
url 'https://jitpack.io'
content {
// Use this repo only for matrix SDK library
includeGroupByRegex "com\\.github\\.Bubu"
// Also add subgroups, due to SDK split into modules
includeGroupByRegex "com\\.github\\.Bubu\\.matrix-android-sdk"
// And Olm library
includeGroupByRegex "org\\.matrix\\.gitlab\\.matrix-org"
}
}
google()
jcenter()
}

View File

@ -9,8 +9,6 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.

View File

@ -1,6 +1,6 @@
#Mon May 03 19:17:08 EDT 2021
#Sun Jan 27 22:19:41 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip