mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-23 17:22:17 -05:00
First hack at client-side sms gateway, receipt works
This commit is contained in:
parent
8f0cd86090
commit
3048d3aaa3
@ -64,11 +64,11 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 25
|
||||
targetSdkVersion 22
|
||||
versionCode 236
|
||||
versionName "1.21.0"
|
||||
archivesBaseName += "-$versionName"
|
||||
applicationId "eu.siacs.conversations"
|
||||
applicationId "eu.siacs.conversations.sms"
|
||||
}
|
||||
|
||||
dexOptions {
|
||||
|
@ -14,6 +14,9 @@
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_PHONE_STATE"
|
||||
@ -218,6 +221,11 @@
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true"/>
|
||||
|
||||
<receiver android:name=".services.SMSReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
package eu.siacs.conversations.services;
|
||||
|
||||
import android.content.*;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.SmsMessage;
|
||||
import android.util.Log;
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
||||
|
||||
public class SMSReceiver extends BroadcastReceiver {
|
||||
|
||||
public static XmppConnectionService xmppConnectionService;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null)
|
||||
return;
|
||||
|
||||
Object[] pdus = (Object[]) bundle.get("pdus");
|
||||
for (int i = 0; i < pdus.length; ++i) {
|
||||
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
|
||||
final String from = msg.getOriginatingAddress();
|
||||
//if (!"7243".equals(msg.getOriginatingAddress())) continue;
|
||||
// it's a message from Page Plus, but is it a balance message?
|
||||
final String message = msg.getMessageBody();
|
||||
if (message == null)
|
||||
continue;
|
||||
// it IS a balance message, get to parsing...
|
||||
Log.d(Config.LOGTAG, "SMSReceiver: " + from + ": " + message);
|
||||
Log.d(Config.LOGTAG, "SMSReceiver: xmppConnectionService: " + xmppConnectionService);
|
||||
try {
|
||||
// test
|
||||
android.widget.Toast.makeText(context, from + ": " + message, android.widget.Toast.LENGTH_SHORT).show();
|
||||
/*
|
||||
*/
|
||||
final Jid fromJid = Jid.fromString(from + "@echo.burtrum.org");
|
||||
final Account account = xmppConnectionService.getAccounts().get(0);
|
||||
|
||||
final MessagePacket packet = new MessagePacket();
|
||||
packet.setType(MessagePacket.TYPE_NORMAL);
|
||||
//packet.setAttribute("id",id);
|
||||
packet.setTo(fromJid);
|
||||
packet.setFrom(account.getJid());
|
||||
|
||||
packet.addChild("echo", "https://code.moparisthebest.com/moparisthebest/xmpp-echo-self");
|
||||
|
||||
final Element forwarded = packet.addChild("forwarded", "urn:xmpp:forward:0");
|
||||
// todo: add delay to forwarded with msg.getTimestampMillis()
|
||||
final MessagePacket forwardedMsg = new MessagePacket();
|
||||
forwarded.addChild(forwardedMsg);
|
||||
|
||||
forwardedMsg.setAttribute("xmlns", "jabber:client");
|
||||
forwardedMsg.setType(MessagePacket.TYPE_CHAT);
|
||||
forwardedMsg.setTo(account.getJid());
|
||||
forwardedMsg.setFrom(fromJid);
|
||||
forwardedMsg.setBody(message);
|
||||
|
||||
xmppConnectionService.sendMessagePacket(account, packet);
|
||||
|
||||
//---send a broadcast intent to update the SMS received in the activity---
|
||||
/*
|
||||
Intent broadcastIntent = new Intent();
|
||||
broadcastIntent.setAction(Main.PP_BAL_RECEIVED_ACTION);
|
||||
broadcastIntent.putExtra(Main.BALANCE, "someString");
|
||||
context.sendBroadcast(broadcastIntent);
|
||||
*/
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(Config.LOGTAG, "SMSReceiver: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -167,6 +167,10 @@ public class XmppConnectionService extends Service {
|
||||
|
||||
private long mLastActivity = 0;
|
||||
|
||||
public XmppConnectionService() {
|
||||
SMSReceiver.xmppConnectionService = this;
|
||||
}
|
||||
|
||||
public DatabaseBackend databaseBackend;
|
||||
private ContentObserver contactObserver = new ContentObserver(null) {
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user