diff --git a/KdeConnect/KdeConnect.iml b/KdeConnect/KdeConnect.iml
index ef070ffd..14b704c8 100644
--- a/KdeConnect/KdeConnect.iml
+++ b/KdeConnect/KdeConnect.iml
@@ -6,6 +6,7 @@
+
@@ -67,9 +68,9 @@
-
-
-
+
+
+
diff --git a/KdeConnect/src/main/AndroidManifest.xml b/KdeConnect/src/main/AndroidManifest.xml
index 8e78a8ac..0a9c3058 100644
--- a/KdeConnect/src/main/AndroidManifest.xml
+++ b/KdeConnect/src/main/AndroidManifest.xml
@@ -54,9 +54,11 @@
+
+
+
-
@@ -65,6 +67,7 @@
-
+
+
diff --git a/KdeConnect/src/main/java/org/kde/connect/BackgroundService.java b/KdeConnect/src/main/java/org/kde/connect/BackgroundService.java
index 0116725a..fe313720 100644
--- a/KdeConnect/src/main/java/org/kde/connect/BackgroundService.java
+++ b/KdeConnect/src/main/java/org/kde/connect/BackgroundService.java
@@ -14,11 +14,11 @@ import org.kde.connect.LinkProviders.AvahiTcpLinkProvider;
import org.kde.connect.LinkProviders.BaseLinkProvider;
import org.kde.connect.PackageInterfaces.BasePackageInterface;
import org.kde.connect.PackageInterfaces.BatteryMonitorPackageInterface;
-import org.kde.connect.PackageInterfaces.CallPackageInterface;
+import org.kde.connect.PackageInterfaces.CallNotificationPackageInterface;
import org.kde.connect.PackageInterfaces.ClipboardPackageInterface;
import org.kde.connect.PackageInterfaces.MprisControlPackageInterface;
import org.kde.connect.PackageInterfaces.PingPackageInterface;
-import org.kde.kdeconnect.R;
+import org.kde.connect.PackageInterfaces.SmsNotificationPackageInterface;
import java.util.ArrayList;
import java.util.HashMap;
@@ -47,21 +47,15 @@ public class BackgroundService extends Service {
Log.e("registerPackageInterfacesFromSettings","registerPackageInterfacesFromSettings");
if (settings.getBoolean("call_interface", true)) {
- addPackageInterface(CallPackageInterface.class);
+ addPackageInterface(CallNotificationPackageInterface.class);
} else {
- removePackageInterface(CallPackageInterface.class);
+ removePackageInterface(CallNotificationPackageInterface.class);
}
- if (settings.getBoolean("ping_interface", true)) {
- addPackageInterface(PingPackageInterface.class);
+ if (settings.getBoolean("sms_interface", true)) {
+ addPackageInterface(SmsNotificationPackageInterface.class);
} else {
- removePackageInterface(PingPackageInterface.class);
- }
-
- if (settings.getBoolean("clipboard_interface", true)) {
- addPackageInterface(ClipboardPackageInterface.class);
- } else {
- removePackageInterface(ClipboardPackageInterface.class);
+ removePackageInterface(SmsNotificationPackageInterface.class);
}
if (settings.getBoolean("battery_interface", true)) {
@@ -70,12 +64,24 @@ public class BackgroundService extends Service {
removePackageInterface(BatteryMonitorPackageInterface.class);
}
+ if (settings.getBoolean("clipboard_interface", true)) {
+ addPackageInterface(ClipboardPackageInterface.class);
+ } else {
+ removePackageInterface(ClipboardPackageInterface.class);
+ }
+
if (settings.getBoolean("mpris_interface", true)) {
addPackageInterface(MprisControlPackageInterface.class);
} else {
removePackageInterface(MprisControlPackageInterface.class);
}
+ if (settings.getBoolean("ping_interface", true)) {
+ addPackageInterface(PingPackageInterface.class);
+ } else {
+ removePackageInterface(PingPackageInterface.class);
+ }
+
}
public BasePackageInterface getPackageInterface(Class c) {
diff --git a/KdeConnect/src/main/java/org/kde/connect/ContactsHelper.java b/KdeConnect/src/main/java/org/kde/connect/ContactsHelper.java
new file mode 100644
index 00000000..2ff3b87a
--- /dev/null
+++ b/KdeConnect/src/main/java/org/kde/connect/ContactsHelper.java
@@ -0,0 +1,45 @@
+package org.kde.connect;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.PhoneLookup;
+import android.util.Log;
+
+public class ContactsHelper {
+
+ public static String phoneNumberLookup(Context context, String number) {
+
+ Log.e("PhoneNumberLookup", number);
+
+ Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
+ Cursor cursor = null;
+ try {
+ cursor = context.getContentResolver().query(
+ uri,
+ new String[] {
+ PhoneLookup.DISPLAY_NAME
+ /*, PhoneLookup.TYPE
+ , PhoneLookup.LABEL
+ , PhoneLookup.ID */
+ },
+ null, null, null);
+ } catch (IllegalArgumentException e) {
+ return number;
+ }
+
+ // Take the first match only
+ if (cursor != null && cursor.moveToFirst()) {
+ int nameIndex = cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
+ if (nameIndex != -1) {
+ String name = cursor.getString(nameIndex);
+ Log.e("PhoneNumberLookup", "success: " + name);
+ return name;
+ }
+ }
+
+ return number;
+
+ }
+}
\ No newline at end of file
diff --git a/KdeConnect/src/main/java/org/kde/connect/NetworkPackage.java b/KdeConnect/src/main/java/org/kde/connect/NetworkPackage.java
index 13475581..51f0c9dd 100644
--- a/KdeConnect/src/main/java/org/kde/connect/NetworkPackage.java
+++ b/KdeConnect/src/main/java/org/kde/connect/NetworkPackage.java
@@ -17,10 +17,14 @@ public class NetworkPackage {
public final static String PACKAGE_TYPE_IDENTITY = "kdeconnect.identity";
public final static String PACKAGE_TYPE_PING = "kdeconnect.ping";
- public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
- public final static String PACKAGE_TYPE_BATTERY = "kdeconnect.battery";
+
public final static String PACKAGE_TYPE_CALL = "kdeconnect.call";
+ //public final static String PACKAGE_TYPE_SMS = "kdeconnect.sms";
+ public final static String PACKAGE_TYPE_BATTERY = "kdeconnect.battery";
+ public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
+
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
+
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
private long mId;
diff --git a/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/BasePackageInterface.java b/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/BasePackageInterface.java
index 03ddf4ac..56b50688 100644
--- a/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/BasePackageInterface.java
+++ b/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/BasePackageInterface.java
@@ -1,5 +1,6 @@
package org.kde.connect.PackageInterfaces;
+import android.content.BroadcastReceiver;
import android.content.Context;
import org.kde.connect.Device;
diff --git a/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/CallPackageInterface.java b/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/CallNotificationPackageInterface.java
similarity index 91%
rename from KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/CallPackageInterface.java
rename to KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/CallNotificationPackageInterface.java
index 1f73cd4f..6e56025b 100644
--- a/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/CallPackageInterface.java
+++ b/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/CallNotificationPackageInterface.java
@@ -5,11 +5,12 @@ import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
+import org.kde.connect.ContactsHelper;
import org.kde.connect.Device;
import org.kde.connect.NetworkPackage;
-public class CallPackageInterface extends BasePackageInterface {
+public class CallNotificationPackageInterface extends BasePackageInterface {
private Context context;
@@ -31,6 +32,7 @@ public class CallPackageInterface extends BasePackageInterface {
lastPackage.set("notificationType", "ringing");
if (phoneNumber != null && !phoneNumber.isEmpty()) {
+ phoneNumber = ContactsHelper.phoneNumberLookup(context,phoneNumber);
lastPackage.set("phoneNumber", phoneNumber);
}
@@ -54,7 +56,8 @@ public class CallPackageInterface extends BasePackageInterface {
//Emit a "call" package
lastPackage = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CALL);
if (phoneNumber != null && !phoneNumber.isEmpty()) {
- lastPackage.set("phoneNumber",phoneNumber);
+ phoneNumber = ContactsHelper.phoneNumberLookup(context,phoneNumber);
+ lastPackage.set("phoneNumber", phoneNumber);
}
sendPackage(lastPackage);
diff --git a/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/SmsNotificationPackageInterface.java b/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/SmsNotificationPackageInterface.java
new file mode 100644
index 00000000..8a0f0a21
--- /dev/null
+++ b/KdeConnect/src/main/java/org/kde/connect/PackageInterfaces/SmsNotificationPackageInterface.java
@@ -0,0 +1,63 @@
+package org.kde.connect.PackageInterfaces;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.telephony.SmsMessage;
+import android.util.Log;
+
+import org.kde.connect.ContactsHelper;
+import org.kde.connect.Device;
+import org.kde.connect.NetworkPackage;
+import org.kde.kdeconnect.R;
+
+public class SmsNotificationPackageInterface extends BasePackageInterface {
+
+ private Context context;
+
+ public void smsBroadcastReceived(SmsMessage message) {
+
+ Log.e("SmsBroadcastReceived", message.toString());
+
+ if (this.context == null) return;
+
+ NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION);
+
+ np.set("notificationType","sms");
+
+ String messageBody = message.getMessageBody();
+ if (messageBody != null) {
+ np.set("messageBody",messageBody);
+ }
+
+ String phoneNumber = message.getOriginatingAddress();
+ if (phoneNumber != null) {
+ phoneNumber = ContactsHelper.phoneNumberLookup(context, phoneNumber);
+ np.set("phoneNumber",phoneNumber);
+ };
+
+ sendPackage(np);
+ }
+
+ @Override
+ public boolean onCreate(Context context) {
+ this.context = context;
+ return true;
+ }
+
+ @Override
+ public void onDestroy() {
+ this.context = null;
+ }
+
+ @Override
+ public boolean onPackageReceived(Device d, NetworkPackage np) {
+ return false;
+ }
+
+ @Override
+ public boolean onDeviceConnected(Device d) {
+ return false;
+ }
+}
diff --git a/KdeConnect/src/main/java/org/kde/connect/ServiceLauncher.java b/KdeConnect/src/main/java/org/kde/connect/ServiceLauncher.java
index 54dea079..e8f7548f 100644
--- a/KdeConnect/src/main/java/org/kde/connect/ServiceLauncher.java
+++ b/KdeConnect/src/main/java/org/kde/connect/ServiceLauncher.java
@@ -7,9 +7,15 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
+import android.os.Bundle;
import android.os.IBinder;
+import android.telephony.SmsMessage;
+import android.telephony.TelephonyManager;
import android.util.Log;
+import org.kde.connect.PackageInterfaces.SmsNotificationPackageInterface;
+import org.kde.kdeconnect.R;
+
public class ServiceLauncher extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
@@ -49,8 +55,29 @@ public class ServiceLauncher extends BroadcastReceiver
}
});
+ } else if(action.equals("android.provider.Telephony.SMS_RECEIVED")) {
+ Log.e("ServiceLauncher","Sms receiver");
+ final Bundle bundle = intent.getExtras();
+ if (bundle == null) return;
+ BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
+ @Override
+ public void onServiceStart(BackgroundService service) {
+ SmsNotificationPackageInterface smsnotify = (SmsNotificationPackageInterface)service.getPackageInterface(SmsNotificationPackageInterface.class);
+ if (smsnotify == null) return;
+ try {
+ Object[] pdus = (Object[]) bundle.get("pdus");
+ for (int i = 0; i < pdus.length; i++) {
+ SmsMessage message = SmsMessage.createFromPdu((byte[])pdus[i]);
+ smsnotify.smsBroadcastReceived(message);
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ Log.e("ServiceLauncher","Sms receiver exception");
+ }
+ }
+ });
} else {
- Log.e("KdeConnect", "Ignoring broadcast event: "+intent.getAction());
+ Log.e("ServiceLauncher", "Ignoring broadcast event: "+intent.getAction());
}
}
diff --git a/KdeConnect/src/main/res/layout/activity_main.xml b/KdeConnect/src/main/res/layout/activity_main.xml
index 3480c962..5b7d5157 100644
--- a/KdeConnect/src/main/res/layout/activity_main.xml
+++ b/KdeConnect/src/main/res/layout/activity_main.xml
@@ -10,8 +10,8 @@
android:orientation="vertical">
+
-
Settings
Call notifications
Send incoming and missed call notifications
- Clipboard sync
- Share the clipboard content
+ SMS notifications
+ Send incoming sms notifications
Battery report
Periodically report battery status
+ Clipboard sync
+ Share the clipboard content
MPRIS controls
Control audio/video from your phone
Pings
Enable sending and receiving ping notifications
+
diff --git a/KdeConnect/src/main/res/xml/settings.xml b/KdeConnect/src/main/res/xml/settings.xml
index 71210111..1304d104 100644
--- a/KdeConnect/src/main/res/xml/settings.xml
+++ b/KdeConnect/src/main/res/xml/settings.xml
@@ -10,15 +10,9 @@
android:defaultValue="true" />
-
-
+
+
+
+
\ No newline at end of file