diff --git a/AndroidManifest.xml b/AndroidManifest.xml --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -22,6 +22,7 @@ + diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.1.3' } } diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java @@ -87,8 +87,8 @@ oldSocket.close(); //This should cancel the readThread } - //Log.e("LanLink", "Start listening"); - //Create a thread to take care of incoming data for the new socket + Log.e("LanLink", "Start listening"); + // Create a thread to take care of incoming data for the new socket new Thread(() -> { try { BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8)); @@ -164,7 +164,7 @@ np = RsaHelper.encrypt(np, key); } - //Log.e("LanLink/sendPacket", np.getType()); + Log.i("LanLink/sendPacket", np.getType()); //Send body of the network package try { diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -99,7 +99,7 @@ //They received my UDP broadcast and are connecting to me. The first thing they sned should be their identity. void tcpPacketReceived(Socket socket) throws Exception { - + Log.i("KDE/LanLinkProvider", "TCP Packet received."); NetworkPacket networkPacket; try { BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); @@ -208,7 +208,7 @@ Log.e("KDE/LanLinkProvider", "Somehow I'm connected to myself, ignoring. This should not happen."); return; } - + Log.i("KDE/LanLinkProvider", "INIT SSL " + identityPacket.getString("deviceName")); // If I'm the TCP server I will be the SSL client and viceversa. final boolean clientMode = (connectionStarted == LanLink.ConnectionStarted.Locally); @@ -296,7 +296,7 @@ //Update old link Log.i("KDE/LanLinkProvider", "Reusing same link for device " + deviceId); final Socket oldSocket = currentLink.reset(socket, connectionOrigin); - //Log.e("KDE/LanLinkProvider", "Replacing socket. old: "+ oldSocket.hashCode() + " - new: "+ socket.hashCode()); + Log.i("KDE/LanLinkProvider", "Replacing socket. old: "+ oldSocket.hashCode() + " - new: "+ socket.hashCode()); } else { Log.i("KDE/LanLinkProvider", "Creating a new link for device " + deviceId); //Let's create the link diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -568,6 +568,7 @@ //If capabilities are not supported, iterate all plugins Collection targetPlugins = pluginsByIncomingInterface.get(np.getType()); + Log.i("PairingPacketReceived", "Type :"+np.getType()); if (targetPlugins != null && !targetPlugins.isEmpty()) { for (String pluginKey : targetPlugins) { Plugin plugin = plugins.get(pluginKey); diff --git a/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java b/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java --- a/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java @@ -15,8 +15,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ + * along with this program. If not, see . + */ package org.kde.kdeconnect.Plugins.PingPlugin; @@ -26,6 +26,8 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.net.Uri; +import android.provider.ContactsContract; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.util.Log; @@ -54,31 +56,36 @@ @Override public boolean onPacketReceived(NetworkPacket np) { + if (!np.getType().equals(PACKET_TYPE_PING)) { Log.e("PingPlugin", "Ping plugin should not receive packets other than pings!"); return false; } - //Log.e("PingPacketReceiver", "was a ping!"); + Log.e("PingPacketReceiver", "was a ping!"); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); - stackBuilder.addNextIntent(new Intent(context, MainActivity.class)); - PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( - 0, - PendingIntent.FLAG_UPDATE_CURRENT - ); int id; String message; if (np.has("message")) { message = np.getString("message"); id = (int) System.currentTimeMillis(); + if (message.startsWith("::DIALER")){ + if (dialer_handler(message,stackBuilder,id)) + return true; + } } else { message = "Ping!"; id = 42; //A unique id to create only one notification } + stackBuilder.addNextIntent(new Intent(context, MainActivity.class)); + PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( + 0, + PendingIntent.FLAG_UPDATE_CURRENT + ); Notification noti = new NotificationCompat.Builder(context) .setContentTitle(device.getName()) .setContentText(message) @@ -96,6 +103,62 @@ } + public boolean dialer_handler(String message,TaskStackBuilder stackBuilder,int notif_id){ + String mparts[] = message.split("::"); + String mtype = mparts[2]; + System.out.println("MTYPE :"+mtype); + String notif_message = "default"; + if (mtype.equals("DIAL")){ + Intent dialer_intent = new Intent(Intent.ACTION_DIAL); + String number = mparts[3]; + dialer_intent.setData(Uri.parse("tel:"+number)); + stackBuilder.addNextIntent(dialer_intent); + notif_message = "Would you like to call "+number; + } + else if (mtype.equals("ADD")){ + + Intent contact_intent = new Intent(ContactsContract.Intents.Insert.ACTION); + contact_intent.setType(ContactsContract.RawContacts.CONTENT_TYPE); + + String name = mparts[3]; + + contact_intent.putExtra(ContactsContract.Intents.Insert.NAME, name); + System.out.println("LEN:"+mparts.length); + switch (mparts.length){ + case 7:contact_intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_PHONE, mparts[6]); + case 6:contact_intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, mparts[5]); + case 5:contact_intent.putExtra(ContactsContract.Intents.Insert.PHONE, mparts[4]);break; + default:return false; + } + stackBuilder.addNextIntent(contact_intent); + notif_message = "Add a new contact '"+ name + "'"; + } + else { + return false; + } + + + PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( + 0, + PendingIntent.FLAG_UPDATE_CURRENT + ); + + Notification noti = new NotificationCompat.Builder(context) + .setContentTitle(device.getName()) + .setContentText(notif_message) + .setContentIntent(resultPendingIntent) + .setTicker(message) + .setSmallIcon(R.drawable.ic_notification) + .setAutoCancel(true) + .setDefaults(Notification.DEFAULT_ALL) + .build(); + + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + NotificationHelper.notifyCompat(notificationManager, notif_id, noti); + return true; + + } + @Override public String getActionName() { return context.getString(R.string.send_ping); @@ -128,4 +191,4 @@ return new String[]{PACKET_TYPE_PING}; } -} +} \ No newline at end of file diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -150,6 +150,7 @@ if (openUrlsDirectly) { context.startActivity(browserIntent); + Log.i("SharePlugin", "Opening Directly: " + url); } else { Resources res = context.getResources(); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); @@ -158,6 +159,7 @@ 0, PendingIntent.FLAG_UPDATE_CURRENT ); + Log.i("SharePlugin", "Opening Notification: " + url); Notification noti = new NotificationCompat.Builder(context) .setContentTitle(res.getString(R.string.received_url_title, device.getName()))