2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 22:25:08 +00:00

Compare commits

..

24 Commits
v0.8e ... v0.8g

Author SHA1 Message Date
Albert Vaca
45bbed6d72 Increased version number to release 2015-04-11 23:53:24 -07:00
Albert Vaca
42f2f425a1 Commented out sendIcons logic until we fix the incomplete file transfers. 2015-04-11 23:53:24 -07:00
Albert Vaca
801c7cbd45 Default priority is not enough to intercept SMS with some apps.
Trying raising it to 500 (maximum is 999).

BUG: 342215
2015-04-11 23:53:24 -07:00
Albert Vaca
366aaea282 Removed unused styles.xml 2015-04-11 23:53:23 -07:00
Albert Vaca
02f5ce2581 Using setSoTimeout instead of implementing the timeout ourselves 2015-04-11 23:53:23 -07:00
l10n daemon script
a360ca0a01 SVN_SILENT made messages (after extraction) 2015-04-12 02:27:37 +00:00
l10n daemon script
d356a9e964 SVN_SILENT made messages (after extraction) 2015-04-08 02:03:18 +00:00
l10n daemon script
e588428812 SVN_SILENT made messages (after extraction) 2015-04-07 02:32:08 +00:00
l10n daemon script
db0f6288ff SVN_SILENT made messages (after extraction) 2015-04-06 02:03:40 +00:00
Albert Vaca
86236169d1 Increase version to release 2015-04-04 18:20:57 -07:00
Albert Vaca
32d9f199ff Let's flush this socket just in case 2015-04-04 18:08:53 -07:00
Albert Vaca
1d51c8792d Do not disconnect the devices when refreshing the listeners
This caused the devices to flicker in the main activity
2015-04-04 17:09:38 -07:00
Albert Vaca
6124b9a206 Minor changes trying to debug discovery issue reported by Aleix on the list 2015-04-04 17:08:26 -07:00
Albert Vaca
c3ad265490 Fixed crash 2015-04-04 14:41:22 -07:00
Albert Vaca
9cf9f43118 Fixes some potential null pointer exceptions reported by Coverity 2015-04-04 14:29:20 -07:00
Albert Vaca
11012e21e5 Added a different notification message for failed file transfers 2015-04-04 14:29:16 -07:00
Albert Vaca
b7faa97292 Handle closing some resources that we were missing to close 2015-04-04 14:29:11 -07:00
Albert Vaca
cc17402609 Fixed NioSocketConnector being kept open after every connection received
And other fixes in the LanLinkProvider
2015-04-04 12:55:52 -07:00
Albert Vaca
a0b82d17b4 Added some logging to help debugging an issue, now commented for future use
Also we prepend KDE/ to these logs to ease filtering them
2015-04-04 11:37:12 -07:00
Albert Vaca
8550de5e7f Coding style 2015-04-04 10:43:49 -07:00
Albert Vaca
46c70639ac Only unpair when receiving unknown packages if I'm not requesting pairing
In case the other device thinks we are paired and answers my identity
packet with unexpected stuff.
2015-03-30 23:26:57 -07:00
l10n daemon script
fb2b1232fb SVN_SILENT made messages (after extraction) 2015-03-31 02:22:21 +00:00
l10n daemon script
c2011831a9 SVN_SILENT made messages (after extraction) 2015-03-30 02:06:46 +00:00
l10n daemon script
ac3ab375ab SVN_SILENT made messages (after extraction) 2015-03-21 02:14:46 +00:00
31 changed files with 346 additions and 252 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.kde.kdeconnect_tp"
android:versionCode="805"
android:versionName="0.8e">
android:versionCode="807"
android:versionName="0.8g">
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="21" />

View File

@@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
classpath 'com.android.tools.build:gradle:1.1.0'
}
}

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">S\'està enviant el fitxer a %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Fitxer rebut des de %1s</string>
<string name="received_file_fail_title">Ha fallat en rebre el fitxer des de %1s</string>
<string name="received_file_text">Puntegeu per obrir «%1s»</string>
<string name="sent_file_title">Envia el fitxer a %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Odesílám soubor do %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Přijat soubor od %1s</string>
<string name="received_file_fail_title">Selhalo přijímání souboru od %1s</string>
<string name="received_file_text">Ťukněte pro otevření \'%1s\'</string>
<string name="sent_file_title">Soubor byl odeslán do %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -8,6 +8,7 @@
<string name="pref_plugin_sftp_desc">Erlaubt das Browsen des Dateisystems auf dem entfernten Handy</string>
<string name="pref_plugin_clipboard">Abgleich der Zwischenablage</string>
<string name="pref_plugin_clipboard_desc">Inhalt der Zwischenablage freigeben</string>
<string name="pref_plugin_mousepad_desc">Verwendet Ihr Handy als Maus und Tastatur</string>
<string name="pref_plugin_mpris">Multimedia-Fernbedienungen</string>
<string name="pref_plugin_mpris_desc">Audio und Video mit Ihrem Telefon steuern</string>
<string name="pref_plugin_ping">Ping</string>
@@ -52,9 +53,12 @@
<string name="received_url_title">Verknüpfung von %1s erhalten</string>
<string name="incoming_file_title">Eingehende Datei von %1s</string>
<string name="incoming_file_text">%1s</string>
<string name="outgoing_file_title">Datei wird an %1s gesendet</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Datei von %1s erhalten</string>
<string name="sent_file_title">Datei an %1s gesendet</string>
<string name="sent_file_text">%1s</string>
<string name="sent_file_failed_title">Das Senden der Datei an %1s ist fehlgeschlagen</string>
<string name="sent_file_failed_text">%1s</string>
<string name="tap_to_answer">Tippen zum Antworten</string>
<string name="reconnect">Erneut verbinden</string>
@@ -94,7 +98,9 @@
<string name="invalid_device_name">Ungültiger Gerätename</string>
<string name="shareplugin_text_saved">Text empfangen und in der Zwischenablage gespeichert</string>
<string name="custom_devices_settings">Benutzerdefinierte Geräteliste</string>
<string name="custom_device_list">Geräte nach IP hinzufügen</string>
<string name="share_notification_preference_summary">Beim Empfang einer Datei vibrieren und einen Sound abspielen</string>
<string name="title_activity_notification_filter">Benachrichtigungs-Filter</string>
<string name="sftp_internal_storage">Interner Speicher</string>
<string name="sftp_all_files">Alle Dateien</string>
<string name="sftp_sdcard_num">SD-Karte %d</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Lähetetään tiedostoa laitteeseen %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Vastaanotettiin tiedosto lähettäjältä %1s</string>
<string name="received_file_fail_title">Ei voitu vastaanottaa tiedostoa lähettäjältä %1s</string>
<string name="received_file_text">Avaa ”%1s” napauttamalla</string>
<string name="sent_file_title">Tiedosto lähetetty laitteeseen %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Invio file a %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">File ricevuto da %1s</string>
<string name="received_file_fail_title">Ricezione file da %1s non riuscita</string>
<string name="received_file_text">Tocca per aprire «%1s»</string>
<string name="sent_file_title">File inviato a %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Bezig bestand te verzenden naar %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Bestand ontvangen van %1s</string>
<string name="received_file_fail_title">Bestand ontvangen van %1s is mislukt</string>
<string name="received_file_text">Tap om \'%1s\' te openen</string>
<string name="sent_file_title">Bestand verzonden naar %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Enviando arquivo para %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Arquivo recebido de %1s</string>
<string name="received_file_fail_title">Falha ao receber o arquivo de %1s</string>
<string name="received_file_text">Toque para abrir o \'%1s\'</string>
<string name="sent_file_title">Enviar arquivo para %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">A enviar o ficheiro para o %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Ficheiro recebido de %1s</string>
<string name="received_file_fail_title">Falhou a recepção do ficheiro de %1s</string>
<string name="received_file_text">Toque para abrir o \'%1s\'</string>
<string name="sent_file_title">O ficheiro foi enviado para %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -27,6 +27,7 @@
<string name="send_ping">Poslať ping</string>
<string name="open_mpris_controls">Otvoriť diaľkové ovládanie</string>
<string name="open_mousepad">Otvoriť ovládanie touchpadu</string>
<string name="mousepad_info">Posúvajte prst na obrazovke na posun kurzora. Ťuknutie vyvolá klik a použite dva/tri prsty pre pravé a stredné tlačidlo. Použite dlhé stlačenie pre drag and drop.</string>
<string name="mousepad_double_tap_settings_title">Nastaviť akciu dvoch prstov</string>
<string name="mousepad_triple_tap_settings_title">Nastaviť akciu troch prstov</string>
<string-array name="mousepad_tap_entries">
@@ -58,10 +59,14 @@
<string name="received_url_text">Ťuknite na otvorenie \'%1s\'</string>
<string name="incoming_file_title">Prichádzajúci súbor od %s</string>
<string name="incoming_file_text">%1s</string>
<string name="outgoing_file_title">Posielam súbor pre %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Prijatý súbor od %1s</string>
<string name="received_file_fail_title">Zlyhalo prijatie súboru od %1s</string>
<string name="received_file_text">Ťuknite na otvorenie \'%1s\'</string>
<string name="sent_file_title">Poslať súbor pre %1s</string>
<string name="sent_file_text">%1s</string>
<string name="sent_file_failed_title">Zlyhalo poslanie súboru %1s</string>
<string name="sent_file_failed_text">%1s</string>
<string name="tap_to_answer">Tapnite na odpoveď</string>
<string name="reconnect">Znovu pripojiť</string>
@@ -83,6 +88,8 @@
<string name="mpris_next">Nasledovné</string>
<string name="mpris_volume">Hlasitosť</string>
<string name="mpris_settings">Multimediálne nastavenia</string>
<string name="mpris_time_settings_title">Tlačidlá dopredu/pretočiť</string>
<string name="mpris_time_settings_summary">Prispôsobiť čas na pretáčanie dopredu alebo dozadu pri stlačení.</string>
<string-array name="mpris_time_entries">
<item>10 sekúnd</item>
<item>20 sekúnd</item>
@@ -104,6 +111,8 @@
<string name="custom_device_list">Pridať zariadenia podľa IP</string>
<string name="share_notification_preference">Hlučné pripomienky</string>
<string name="share_notification_preference_summary">Vibrovať a prehrať zvuk pri prijatí súboru</string>
<string name="title_activity_notification_filter">Filter upozornení</string>
<string name="filter_apps_info">Upozornenia budú synchronizované pre vybrané aplikácie.</string>
<string name="sftp_internal_storage">Interné úložisko</string>
<string name="sftp_all_files">Všetky súbory</string>
<string name="sftp_sdcard_num">SD karta %d</string>
@@ -111,6 +120,7 @@
<string name="sftp_readonly">(iba na čítanie)</string>
<string name="sftp_camera">Obrázky fotoaparátu</string>
<string name="add_host">Pridať hostiteľa/IP</string>
<string name="add_host_hint">Názov hostiteľa alebo IP</string>
<string name="no_players_connected">Nenašli sa žiadne prehrávače</string>
<string name="custom_dev_list_help">Túto voľbu použite iba vtedy, ak vaše zariadenie nie je automaticky detekované. Zadajte IP adresu alebo názov hostiteľa nižšie a kliknite na tlačidlo na pridanie do zoznamu. Kliknite na existujúcu položku na odstránenie jej zo zoznamu.</string>
<string name="mpris_player_on_device">%1$s na %2$s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Skickar fil till %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Tog emot fil från %1s</string>
<string name="received_file_fail_title">Misslyckades ta emot fil från %1s</string>
<string name="received_file_text">Rör för att öppna \'%1s\'</string>
<string name="sent_file_title">Skickade fil till %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -62,6 +62,7 @@
<string name="outgoing_file_title">Надсилаємо файл до %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Отримано файл з %1s</string>
<string name="received_file_fail_title">Не вдалося отримати файл з %1s</string>
<string name="received_file_text">Натисніть, щоб відкрити «%1s»</string>
<string name="sent_file_title">Файл надіслано до %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -1,11 +0,0 @@
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

View File

@@ -70,6 +70,7 @@
<string name="outgoing_file_title">Sending file to %1s</string>
<string name="outgoing_file_text">%1s</string>
<string name="received_file_title">Received file from %1s</string>
<string name="received_file_fail_title">Failed receiving file from %1s</string>
<string name="received_file_text">Tap to open \'%1s\'</string>
<string name="sent_file_title">Sent file to %1s</string>
<string name="sent_file_text">%1s</string>

View File

@@ -46,13 +46,13 @@ public abstract class BaseLinkProvider {
//These two should be called when the provider links to a new computer
protected void connectionAccepted(NetworkPackage identityPackage, BaseLink link) {
Log.i("LinkProvider", "connectionAccepted");
//Log.i("KDE/LinkProvider", "connectionAccepted");
for(ConnectionReceiver cr : connectionReceivers) {
cr.onConnectionReceived(identityPackage, link);
}
}
protected void connectionLost(BaseLink link) {
Log.i("LinkProvider", "connectionLost");
//Log.i("KDE/LinkProvider", "connectionLost");
for(ConnectionReceiver cr : connectionReceivers) {
cr.onConnectionLost(link);
}

View File

@@ -47,8 +47,10 @@ public class LanLink extends BaseLink {
private IoSession session = null;
public void disconnect() {
if (session == null) return;
//Log.i("LanLink", "Disconnect: "+session.getRemoteAddress().toString());
if (session == null) {
Log.e("KDE/LanLink", "Not yet connected");
return;
}
session.close(true);
}
@@ -60,7 +62,7 @@ public class LanLink extends BaseLink {
//Blocking, do not call from main thread
private void sendPackageInternal(NetworkPackage np, final Device.SendPackageStatusCallback callback, PublicKey key) {
if (session == null) {
Log.e("sendPackage", "Not yet connected");
Log.e("KDE/sendPackage", "Not yet connected");
callback.sendFailure(new NotYetConnectedException());
return;
}
@@ -87,7 +89,7 @@ public class LanLink extends BaseLink {
WriteFuture future = session.write(np.serialize());
future.awaitUninterruptibly();
if (!future.isWritten()) {
Log.e("sendPackage", "!future.isWritten()");
Log.e("KDE/sendPackage", "!future.isWritten()");
callback.sendFailure(future.getException());
return;
}
@@ -97,19 +99,10 @@ public class LanLink extends BaseLink {
OutputStream socket = null;
try {
//Wait a maximum of 10 seconds for the other end to establish a connection with our socket, close it afterwards
Timer timeout = new Timer();
timeout.schedule(new TimerTask() {
@Override
public void run() {
Log.e("sendPackage","Timeout");
try { server.close(); } catch (Exception e) { }
callback.sendFailure(new TimeoutException("Timed out waiting for other end to establish a connection to receive the payload."));
}
},10*1000);
server.setSoTimeout(10*1000);
socket = server.accept().getOutputStream();
timeout.cancel();
Log.i("LanLink", "Beginning to send payload");
Log.i("KDE/LanLink", "Beginning to send payload");
byte[] buffer = new byte[4096];
int bytesRead;
@@ -123,9 +116,11 @@ public class LanLink extends BaseLink {
callback.sendProgress((int)(progress / np.getPayloadSize()));
}
}
Log.i("LanLink", "Finished sending payload");
socket.flush();
stream.close();
Log.i("KDE/LanLink", "Finished sending payload ("+progress+" bytes written)");
} catch (Exception e) {
Log.e("sendPackage", "Exception: "+e);
Log.e("KDE/sendPackage", "Exception: "+e);
callback.sendFailure(e);
return;
} finally {
@@ -167,22 +162,24 @@ public class LanLink extends BaseLink {
np = np.decrypt(privateKey);
} catch(Exception e) {
e.printStackTrace();
Log.e("onPackageReceived","Exception reading the key needed to decrypt the package");
Log.e("KDE/onPackageReceived","Exception reading the key needed to decrypt the package");
}
}
if (np.hasPayloadTransferInfo()) {
Socket socket = null;
try {
Socket socket = new Socket();
socket = new Socket();
int tcpPort = np.getPayloadTransferInfo().getInt("port");
InetSocketAddress address = (InetSocketAddress)session.getRemoteAddress();
socket.connect(new InetSocketAddress(address.getAddress(), tcpPort));
np.setPayload(socket.getInputStream(), np.getPayloadSize());
} catch (Exception e) {
try { socket.close(); } catch(Exception ignored) { }
e.printStackTrace();
Log.e("LanLink", "Exception connecting to payload remote socket");
Log.e("KDE/LanLink", "Exception connecting to payload remote socket");
}
}
@@ -200,12 +197,12 @@ public class LanLink extends BaseLink {
candidateServer = new ServerSocket();
candidateServer.bind(new InetSocketAddress(tcpPort));
success = true;
Log.i("LanLink", "Using port "+tcpPort);
Log.i("KDE/LanLink", "Using port "+tcpPort);
} catch(IOException e) {
//Log.e("LanLink", "Exception openning serversocket: "+e);
tcpPort++;
if (tcpPort >= 1764) {
Log.e("LanLink", "No more ports available");
Log.e("KDE/LanLink", "No more ports available");
throw e;
}
}

View File

@@ -21,7 +21,6 @@
package org.kde.kdeconnect.Backends.LanBackend;
import android.content.Context;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v4.util.LongSparseArray;
import android.util.Log;
@@ -47,9 +46,11 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
public class LanLinkProvider extends BaseLinkProvider {
@@ -59,6 +60,7 @@ public class LanLinkProvider extends BaseLinkProvider {
private final Context context;
private final HashMap<String, LanLink> visibleComputers = new HashMap<String, LanLink>();
private final LongSparseArray<LanLink> nioSessions = new LongSparseArray<LanLink>();
private final LongSparseArray<NioSocketConnector> nioConnectors = new LongSparseArray<NioSocketConnector>();
private NioSocketAcceptor tcpAcceptor = null;
private NioDatagramAcceptor udpAcceptor = null;
@@ -66,29 +68,46 @@ public class LanLinkProvider extends BaseLinkProvider {
private final IoHandler tcpHandler = new IoHandlerAdapter() {
@Override
public void sessionClosed(IoSession session) throws Exception {
final LanLink brokenLink = nioSessions.get(session.getId());
if (brokenLink != null) {
nioSessions.remove(session.getId());
brokenLink.disconnect();
String deviceId = brokenLink.getDeviceId();
if (visibleComputers.get(deviceId) == brokenLink) {
visibleComputers.remove(deviceId);
try {
long id = session.getId();
final LanLink brokenLink = nioSessions.get(id);
NioSocketConnector connector = nioConnectors.get(id);
if (connector != null) {
connector.dispose();
nioConnectors.remove(id);
}
new Thread(new Runnable() {
@Override
public void run() {
//Wait a bit before emiting connectionLost, in case the same device re-appears
try {
Thread.sleep(200);
} catch (InterruptedException e) { }
connectionLost(brokenLink);
if (brokenLink != null) {
nioSessions.remove(id);
//Log.i("KDE/LanLinkProvider", "nioSessions.size(): " + nioSessions.size() + " (-)");
try {
brokenLink.disconnect();
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/LanLinkProvider", "Exception. Already disconnected?");
}
}).start();
//Log.i("KDE/LanLinkProvider", "Disconnected!");
String deviceId = brokenLink.getDeviceId();
if (visibleComputers.get(deviceId) == brokenLink) {
visibleComputers.remove(deviceId);
}
new Thread(new Runnable() {
@Override
public void run() {
//Wait a bit before emiting connectionLost, in case the same device re-appears
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
connectionLost(brokenLink);
}
}).start();
}
} catch (Exception e) { //If we don't catch it here, Mina will swallow it :/
e.printStackTrace();
Log.e("KDE/LanLinkProvider", "sessionClosed exception");
}
}
@Override
@@ -100,7 +119,7 @@ public class LanLinkProvider extends BaseLinkProvider {
String theMessage = (String) message;
if (theMessage.isEmpty()) {
Log.e("LanLinkProvider","Empty package received");
Log.e("KDE/LanLinkProvider","Empty package received");
return;
}
@@ -113,15 +132,16 @@ public class LanLinkProvider extends BaseLinkProvider {
return;
}
//Log.e("LanLinkProvider", "Identity package received from "+np.getString("deviceName"));
//Log.i("KDE/LanLinkProvider", "Identity package received from " + np.getString("deviceName"));
LanLink link = new LanLink(session, np.getString("deviceId"), LanLinkProvider.this);
nioSessions.put(session.getId(),link);
//Log.e("KDE/LanLinkProvider","nioSessions.size(): " + nioSessions.size());
addLink(np, link);
} else {
LanLink prevLink = nioSessions.get(session.getId());
if (prevLink == null) {
Log.e("LanLinkProvider","2 Expecting an identity package");
Log.e("KDE/LanLinkProvider","Expecting an identity package (A)");
} else {
prevLink.injectNetworkPackage(np);
}
@@ -143,7 +163,7 @@ public class LanLinkProvider extends BaseLinkProvider {
final NetworkPackage identityPackage = NetworkPackage.unserialize(theMessage);
if (!identityPackage.getType().equals(NetworkPackage.PACKAGE_TYPE_IDENTITY)) {
Log.e("LanLinkProvider", "1 Expecting an identity package");
Log.e("KDE/LanLinkProvider", "Expecting an identity package (B)");
return;
} else {
String myId = NetworkPackage.createIdentityPackage(context).getString("deviceId");
@@ -152,7 +172,7 @@ public class LanLinkProvider extends BaseLinkProvider {
}
}
Log.i("LanLinkProvider", "Identity package received, creating link");
//Log.i("KDE/LanLinkProvider", "Identity package received, creating link");
final InetSocketAddress address = (InetSocketAddress) udpSession.getRemoteAddress();
@@ -164,42 +184,48 @@ public class LanLinkProvider extends BaseLinkProvider {
textLineFactory.setDecoderMaxLineLength(512*1024); //Allow to receive up to 512kb of data
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(textLineFactory));
int tcpPort = identityPackage.getInt("tcpPort",port);
ConnectFuture future = connector.connect(new InetSocketAddress(address.getAddress(), tcpPort));
int tcpPort = identityPackage.getInt("tcpPort", port);
final ConnectFuture future = connector.connect(new InetSocketAddress(address.getAddress(), tcpPort));
future.addListener(new IoFutureListener<IoFuture>() {
@Override
public void operationComplete(IoFuture ioFuture) {
final IoSession session = ioFuture.getSession();
try {
future.removeListener(this);
final IoSession session = ioFuture.getSession();
Log.i("KDE/LanLinkProvider", "Connection successful: " + session.isConnected());
final LanLink link = new LanLink(session, identityPackage.getString("deviceId"), LanLinkProvider.this);
final LanLink link = new LanLink(session, identityPackage.getString("deviceId"), LanLinkProvider.this);
new Thread(new Runnable() {
@Override
public void run() {
NetworkPackage np2 = NetworkPackage.createIdentityPackage(context);
link.sendPackage(np2,new Device.SendPackageStatusCallback() {
@Override
protected void onSuccess() {
nioSessions.put(session.getId(), link);
nioConnectors.put(session.getId(), connector);
//Log.e("KDE/LanLinkProvider","nioSessions.size(): " + nioSessions.size());
addLink(identityPackage, link);
}
Log.i("LanLinkProvider", "Connection successful: " + session.isConnected());
new Thread(new Runnable() {
@Override
public void run() {
NetworkPackage np2 = NetworkPackage.createIdentityPackage(context);
link.sendPackage(np2,new Device.SendPackageStatusCallback() {
@Override
protected void onSuccess() {
nioSessions.put(session.getId(), link);
addLink(identityPackage, link);
}
@Override
protected void onFailure(Throwable e) {
}
});
}
}).start();
@Override
protected void onFailure(Throwable e) {
Log.e("KDE/LanLinkProvider", "Connection failed: could not send identity package back");
}
});
}
}).start();
} catch (Exception e) { //If we don't catch it here, Mina will swallow it :/
e.printStackTrace();
Log.e("KDE/LanLinkProvider", "sessionClosed exception");
}
}
});
} catch (Exception e) {
Log.e("LanLinkProvider","Exception receiving udp package!!");
Log.e("KDE/LanLinkProvider","Exception receiving udp package!!");
e.printStackTrace();
}
@@ -208,16 +234,16 @@ public class LanLinkProvider extends BaseLinkProvider {
private void addLink(NetworkPackage identityPackage, LanLink link) {
String deviceId = identityPackage.getString("deviceId");
Log.i("LanLinkProvider","addLink to "+deviceId);
Log.i("KDE/LanLinkProvider","addLink to "+deviceId);
LanLink oldLink = visibleComputers.get(deviceId);
if (oldLink == link) {
Log.e("KDEConnect", "LanLinkProvider: oldLink == link. This should not happen!");
Log.e("KDE/LanLinkProvider", "oldLink == link. This should not happen!");
return;
}
visibleComputers.put(deviceId, link);
connectionAccepted(identityPackage, link);
if (oldLink != null) {
Log.i("LanLinkProvider","Removing old connection to same device");
Log.i("KDE/LanLinkProvider","Removing old connection to same device");
oldLink.disconnect();
connectionLost(oldLink);
}
@@ -232,13 +258,11 @@ public class LanLinkProvider extends BaseLinkProvider {
tcpAcceptor.setHandler(tcpHandler);
tcpAcceptor.getSessionConfig().setKeepAlive(true);
tcpAcceptor.getSessionConfig().setReuseAddress(true);
tcpAcceptor.setCloseOnDeactivation(false);
//TextLineCodecFactory will buffer incoming data and emit a message very time it finds a \n
TextLineCodecFactory textLineFactory = new TextLineCodecFactory(Charset.defaultCharset(), LineDelimiter.UNIX, LineDelimiter.UNIX);
textLineFactory.setDecoderMaxLineLength(512*1024); //Allow to receive up to 512kb of data
tcpAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(textLineFactory));
udpAcceptor = new NioDatagramAcceptor();
udpAcceptor.getSessionConfig().setReuseAddress(true); //Share port if existing
//TextLineCodecFactory will buffer incoming data and emit a message very time it finds a \n
@@ -256,12 +280,19 @@ public class LanLinkProvider extends BaseLinkProvider {
//This handles the case when I'm the existing device in the network and receive a "hello" UDP package
Set<SocketAddress> addresses = udpAcceptor.getLocalAddresses();
for (SocketAddress address : addresses) {
Log.i("KDE/LanLinkProvider", "UDP unbind old address");
udpAcceptor.unbind(address);
}
//Log.i("KDE/LanLinkProvider", "UDP Bind.");
udpAcceptor.setHandler(udpHandler);
try {
udpAcceptor.bind(new InetSocketAddress(port));
} catch(Exception e) {
Log.e("LanLinkProvider", "Error: Could not bind udp socket");
Log.e("KDE/LanLinkProvider", "Error: Could not bind udp socket");
e.printStackTrace();
}
@@ -276,50 +307,73 @@ public class LanLinkProvider extends BaseLinkProvider {
}
}
Log.i("LanLinkProvider","Using tcpPort "+tcpPort);
Log.i("KDE/LanLinkProvider","Using tcpPort "+tcpPort);
//I'm on a new network, let's be polite and introduce myself
final int finalTcpPort = tcpPort;
new AsyncTask<Void,Void,Void>() {
new Thread(new Runnable() {
@Override
protected Void doInBackground(Void... voids) {
public void run() {
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(
KEY_CUSTOM_DEVLIST_PREFERENCE, "");
ArrayList<String> iplist = new ArrayList<String>();
if (!deviceListPrefs.isEmpty()) {
iplist = CustomDevicesActivity.deserializeIpList(deviceListPrefs);
}
iplist.add("255.255.255.255");
for (String ipstr : iplist) {
try {
InetAddress client = InetAddress.getByName(ipstr);
NetworkPackage identity = NetworkPackage.createIdentityPackage(context);
identity.set("tcpPort", finalTcpPort);
byte[] b = identity.serialize().getBytes("UTF-8");
DatagramPacket packet = new DatagramPacket(b, b.length, client, port);
DatagramSocket socket = new DatagramSocket();
socket.setReuseAddress(true);
socket.setBroadcast(true);
socket.send(packet);
//Log.i("LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
} catch(Exception e) {
e.printStackTrace();
Log.e("LanLinkProvider","Sending udp identity package failed. Invalid address? ("+ipstr+")");
iplist.add("255.255.255.255"); //Default: broadcast.
NetworkPackage identity = NetworkPackage.createIdentityPackage(context);
identity.set("tcpPort", finalTcpPort);
DatagramSocket socket = null;
byte[] bytes = null;
try {
socket = new DatagramSocket();
socket.setReuseAddress(true);
socket.setBroadcast(true);
bytes = identity.serialize().getBytes("UTF-8");
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/LanLinkProvider","Failed to create DatagramSocket");
}
if (bytes != null) {
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
for (String ipstr : iplist) {
try {
InetAddress client = InetAddress.getByName(ipstr);
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port);
socket.send(packet);
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")");
}
}
}
return null;
socket.close();
}
}.execute();
}).start();
}
@Override
public void onNetworkChange() {
//Log.e("KDE/LanLinkProvider","onNetworkChange");
//FilesHelper.LogOpenFileCount();
//Keep existing connections open while unbinding the socket
tcpAcceptor.setCloseOnDeactivation(false);
onStop();
tcpAcceptor.setCloseOnDeactivation(true);
//FilesHelper.LogOpenFileCount();
onStart();
//FilesHelper.LogOpenFileCount();
}
@Override
@@ -327,14 +381,12 @@ public class LanLinkProvider extends BaseLinkProvider {
udpAcceptor.unbind();
tcpAcceptor.unbind();
}
/*
@Override
public int getPriority() {
return 1000;
}
*/
@Override
public String getName() {
return "LanLinkProvider";
}
}

View File

@@ -105,17 +105,17 @@ public class BackgroundService extends Service {
@Override
public void onConnectionReceived(final NetworkPackage identityPackage, final BaseLink link) {
Log.i("BackgroundService", "Connection accepted!");
Log.i("KDE/BackgroundService", "Connection accepted!");
String deviceId = identityPackage.getString("deviceId");
Device device = devices.get(deviceId);
if (device != null) {
Log.i("BackgroundService", "addLink, known device: " + deviceId);
Log.i("KDE/BackgroundService", "addLink, known device: " + deviceId);
device.addLink(identityPackage, link);
} else {
Log.i("BackgroundService", "addLink,unknown device: " + deviceId);
Log.i("KDE/BackgroundService", "addLink,unknown device: " + deviceId);
device = new Device(BackgroundService.this, identityPackage, link);
devices.put(deviceId, device);
device.addPairingCallback(devicePairingCallback);
@@ -127,7 +127,7 @@ public class BackgroundService extends Service {
@Override
public void onConnectionLost(BaseLink link) {
Device d = devices.get(link.getDeviceId());
Log.i("onConnectionLost", "removeLink, deviceId: " + link.getDeviceId());
Log.i("KDE/onConnectionLost", "removeLink, deviceId: " + link.getDeviceId());
if (d != null) {
d.removeLink(link);
if (!d.isReachable() && !d.isPaired()) {
@@ -136,7 +136,7 @@ public class BackgroundService extends Service {
d.removePairingCallback(devicePairingCallback);
}
} else {
Log.e("onConnectionLost","Removing connection to unknown device, this should not happen");
Log.e("KDE/onConnectionLost","Removing connection to unknown device, this should not happen");
}
if (deviceListChangedCallback != null) deviceListChangedCallback.onDeviceListChanged();
}
@@ -147,34 +147,35 @@ public class BackgroundService extends Service {
}
public void startDiscovery() {
Log.i("BackgroundService","StartDiscovery");
Log.i("KDE/BackgroundService","StartDiscovery");
for (BaseLinkProvider a : linkProviders) {
a.onStart();
}
}
public void stopDiscovery() {
Log.i("BackgroundService","StopDiscovery");
Log.i("KDE/BackgroundService","StopDiscovery");
for (BaseLinkProvider a : linkProviders) {
a.onStop();
}
}
public void onNetworkChange() {
Log.i("BackgroundService","OnNetworkChange");
Log.i("KDE/BackgroundService","OnNetworkChange");
for (BaseLinkProvider a : linkProviders) {
a.onNetworkChange();
}
}
public void addConnectionListener(BaseLinkProvider.ConnectionReceiver cr) {
Log.i("BackgroundService","Registering connection listener");
Log.i("KDE/BackgroundService","Registering connection listener");
for (BaseLinkProvider a : linkProviders) {
a.addConnectionReceiver(cr);
}
}
public void removeConnectionListener(BaseLinkProvider.ConnectionReceiver cr) {
Log.i("KDE/BackgroundService","Removing connection listener");
for (BaseLinkProvider a : linkProviders) {
a.removeConnectionReceiver(cr);
}
@@ -198,7 +199,7 @@ public class BackgroundService extends Service {
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
registerReceiver(new KdeConnectBroadcastReceiver(), filter);
Log.i("BackgroundService","Service not started yet, initializing...");
Log.i("KDE/BackgroundService","Service not started yet, initializing...");
initializeRsaKeys();
MainSettingsActivity.initializeDeviceName(this);
@@ -223,7 +224,7 @@ public class BackgroundService extends Service {
keyPair = keyGen.genKeyPair();
} catch(Exception e) {
e.printStackTrace();
Log.e("initializeRsaKeys","Exception");
Log.e("KDE/initializeRsaKeys","Exception");
return;
}
@@ -268,7 +269,7 @@ public class BackgroundService extends Service {
@Override
public void onDestroy() {
Log.i("BackgroundService", "Destroying");
Log.i("KDE/BackgroundService", "Destroying");
stopDiscovery();
super.onDestroy();
}

View File

@@ -102,7 +102,7 @@ public class Device implements BaseLink.PackageReceiver {
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes));
} catch (Exception e) {
e.printStackTrace();
Log.e("Device","Exception");
Log.e("KDE/Device","Exception");
}
reloadPluginsFromSettings();
@@ -200,7 +200,7 @@ public class Device implements BaseLink.PackageReceiver {
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_timed_out));
}
Log.e("Device","Unpairing (timeout A)");
Log.e("KDE/Device","Unpairing (timeout A)");
pairStatus = PairStatus.NotPaired;
}
}, 30*1000); //Time to wait for the other to accept
@@ -212,7 +212,7 @@ public class Device implements BaseLink.PackageReceiver {
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_could_not_send_package));
}
Log.e("Device","Unpairing (sendFailed A)");
Log.e("KDE/Device","Unpairing (sendFailed A)");
pairStatus = PairStatus.NotPaired;
}
@@ -271,7 +271,7 @@ public class Device implements BaseLink.PackageReceiver {
public void acceptPairing() {
Log.i("Device","Accepted pair request started by the other device");
Log.i("KDE/Device","Accepted pair request started by the other device");
//Send our own public key
NetworkPackage np = NetworkPackage.createPublicKeyPackage(context);
@@ -294,7 +294,7 @@ public class Device implements BaseLink.PackageReceiver {
public void rejectPairing() {
Log.i("Device","Rejected pair request started by the other device");
Log.i("KDE/Device","Rejected pair request started by the other device");
//Log.e("Device","Unpairing (rejectPairing)");
pairStatus = PairStatus.NotPaired;
@@ -321,6 +321,7 @@ public class Device implements BaseLink.PackageReceiver {
}
public void addLink(NetworkPackage identityPackage, BaseLink link) {
//FilesHelper.LogOpenFileCount();
this.protocolVersion = identityPackage.getInt("protocolVersion");
@@ -341,10 +342,10 @@ public class Device implements BaseLink.PackageReceiver {
link.setPrivateKey(privateKey);
} catch (Exception e) {
e.printStackTrace();
Log.e("Device", "Exception reading our own private key"); //Should not happen
Log.e("KDE/Device", "Exception reading our own private key"); //Should not happen
}
Log.i("Device","addLink "+link.getLinkProvider().getName()+" -> "+getName() + " active links: "+ links.size());
Log.i("KDE/Device","addLink "+link.getLinkProvider().getName()+" -> "+getName() + " active links: "+ links.size());
/*
Collections.sort(links, new Comparator<BaseLink>() {
@@ -363,9 +364,11 @@ public class Device implements BaseLink.PackageReceiver {
}
public void removeLink(BaseLink link) {
//FilesHelper.LogOpenFileCount();
link.removePackageReceiver(this);
links.remove(link);
Log.i("Device","removeLink: "+link.getLinkProvider().getName() + " -> "+getName() + " active links: "+ links.size());
Log.i("KDE/Device","removeLink: "+link.getLinkProvider().getName() + " -> "+getName() + " active links: "+ links.size());
if (links.isEmpty()) {
reloadPluginsFromSettings();
}
@@ -376,7 +379,7 @@ public class Device implements BaseLink.PackageReceiver {
if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR)) {
Log.i("Device","Pair package");
Log.i("KDE/Device","Pair package");
boolean wantsPair = np.getBoolean("pair");
@@ -401,7 +404,7 @@ public class Device implements BaseLink.PackageReceiver {
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes));
} catch(Exception e) {
e.printStackTrace();
Log.e("Device","Pairing exception: Received incorrect key");
Log.e("KDE/Device","Pairing exception: Received incorrect key");
for (PairingCallback cb : pairingCallback) {
cb.pairingFailed(context.getString(R.string.error_invalid_key));
}
@@ -410,7 +413,7 @@ public class Device implements BaseLink.PackageReceiver {
if (pairStatus == PairStatus.Requested) { //We started pairing
Log.i("Pairing","Pair answer");
Log.i("KDE/Pairing","Pair answer");
if (pairingTimer != null) pairingTimer.cancel();
@@ -418,7 +421,7 @@ public class Device implements BaseLink.PackageReceiver {
} else {
Log.i("Pairing","Pair request");
Log.i("KDE/Pairing","Pair request");
Intent intent = new Intent(context, PairActivity.class);
intent.putExtra("deviceId", deviceId);
@@ -447,7 +450,7 @@ public class Device implements BaseLink.PackageReceiver {
pairingTimer.schedule(new TimerTask() {
@Override
public void run() {
Log.e("Device","Unpairing (timeout B)");
Log.e("KDE/Device","Unpairing (timeout B)");
pairStatus = PairStatus.NotPaired;
notificationManager.cancel(notificationId);
}
@@ -457,7 +460,7 @@ public class Device implements BaseLink.PackageReceiver {
}
} else {
Log.i("Pairing","Unpair request");
Log.i("KDE/Pairing","Unpair request");
if (pairStatus == PairStatus.Requested) {
pairingTimer.cancel();
@@ -470,27 +473,30 @@ public class Device implements BaseLink.PackageReceiver {
reloadPluginsFromSettings();
}
//Log.e("Device","Unpairing (unpair request)");
pairStatus = PairStatus.NotPaired;
for (PairingCallback cb : pairingCallback) cb.unpaired();
}
} else if (!isPaired()) {
unpair();
Log.e("onPackageReceived","Device not paired, ignoring package!");
} else {
} else if (isPaired()) {
for (Plugin plugin : plugins.values()) {
try {
plugin.onPackageReceived(np);
} catch (Exception e) {
e.printStackTrace();
Log.e("Device", "Exception in "+plugin.getDisplayName()+"'s onPackageReceived()");
Log.e("KDE/Device", "Exception in "+plugin.getDisplayName()+"'s onPackageReceived()");
}
}
} else {
Log.e("KDE/onPackageReceived","Device not paired, ignoring package!");
if (pairStatus != PairStatus.Requested) {
unpair();
}
}
}
@@ -508,9 +514,9 @@ public class Device implements BaseLink.PackageReceiver {
public void sendFailure(Throwable e) {
if (e != null) {
e.printStackTrace();
Log.e("sendPackage", "Exception: " + e.getMessage());
Log.e("KDE/sendPackage", "Exception: " + e.getMessage());
} else {
Log.e("sendPackage", "Unknown (null) exception");
Log.e("KDE/sendPackage", "Unknown (null) exception");
}
onFailure(e);
}
@@ -543,6 +549,7 @@ public class Device implements BaseLink.PackageReceiver {
//Make a copy to avoid concurrent modification exception if the original list changes
ArrayList<BaseLink> mLinks = new ArrayList<BaseLink>(links);
for (final BaseLink link : mLinks) {
if (link == null) continue; //Since we made a copy, maybe somebody destroyed the link in the meanwhile
if (useEncryption) {
link.sendPackageEncrypted(np, callback, publicKey);
} else {
@@ -552,7 +559,7 @@ public class Device implements BaseLink.PackageReceiver {
}
if (!callback.success) {
Log.e("sendPackage", "No device link (of "+mLinks.size()+" available) could send the package. Package lost!");
Log.e("KDE/sendPackage", "No device link (of "+mLinks.size()+" available) could send the package. Package lost!");
backtrace.printStackTrace();
}
@@ -580,13 +587,13 @@ public class Device implements BaseLink.PackageReceiver {
private synchronized void addPlugin(final String name) {
Plugin existing = plugins.get(name);
if (existing != null) {
Log.w("addPlugin","plugin already present:" + name);
Log.w("KDE/addPlugin","plugin already present:" + name);
return;
}
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, name, this);
if (plugin == null) {
Log.e("addPlugin","could not instantiate plugin: "+name);
Log.e("KDE/addPlugin","could not instantiate plugin: "+name);
failedPlugins.put(name, plugin);
return;
}
@@ -601,7 +608,7 @@ public class Device implements BaseLink.PackageReceiver {
} catch (Exception e) {
success = false;
e.printStackTrace();
Log.e("addPlugin", "Exception loading plugin " + name);
Log.e("KDE/addPlugin", "Exception loading plugin " + name);
}
if (success) {
@@ -609,7 +616,7 @@ public class Device implements BaseLink.PackageReceiver {
failedPlugins.remove(name);
plugins.put(name, plugin);
} else {
Log.e("addPlugin", "plugin failed to load " + name);
Log.e("KDE/addPlugin", "plugin failed to load " + name);
plugins.remove(name);
failedPlugins.put(name, plugin);
}
@@ -641,7 +648,7 @@ public class Device implements BaseLink.PackageReceiver {
//Log.e("removePlugin","removed " + name);
} catch (Exception e) {
e.printStackTrace();
Log.e("removePlugin","Exception calling onDestroy for plugin "+name);
Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+name);
}
for (PluginsChangedListener listener : pluginsChangedListeners) {

View File

@@ -20,8 +20,11 @@
package org.kde.kdeconnect.Helpers;
import android.util.Log;
import android.webkit.MimeTypeMap;
import java.io.File;
public class FilesHelper {
public static String getFileExt(String fileName) {
@@ -73,4 +76,11 @@ public class FilesHelper {
return toFileSystemSafeName(name, true, 255);
}
public static int GetOpenFileCount() {
return new File("/proc/self/fd").listFiles().length;
}
public static void LogOpenFileCount() {
Log.e("KDE/FileCount",""+GetOpenFileCount());
}
}

View File

@@ -81,7 +81,9 @@ public class StorageHelper {
if (storage.exists() && storage.isDirectory()) {
String mounts = null;
try {
mounts = new Scanner( new File("/proc/mounts") ).useDelimiter("\\A").next();
Scanner scanner = new Scanner( new File("/proc/mounts") );
mounts = scanner.useDelimiter("\\A").next();
scanner.close();
//Log.e("Mounts",mounts);
} catch(Exception e) {
e.printStackTrace();

View File

@@ -64,13 +64,14 @@ public class NotificationFilterActivity extends ActionBarActivity {
res.moveToNext();
i++;
}
res.close();
appDatabase.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,android.R.id.text1, appName);
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
for (i = 0 ; i < res.getCount(); i++){
for (i = 0 ; i < isFiltered.length; i++){
if (isFiltered[i]) {
listView.setItemChecked(i, true);
}
@@ -85,6 +86,7 @@ public class NotificationFilterActivity extends ActionBarActivity {
appDatabase.close();
}
});
}
// Delete apps from database which are uninstalled
@@ -101,6 +103,7 @@ public class NotificationFilterActivity extends ActionBarActivity {
}
res.moveToNext();
}
res.close();
}
appDatabase.close();

View File

@@ -25,7 +25,6 @@ import android.app.AlertDialog;
import android.app.Notification;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
@@ -35,19 +34,16 @@ import android.util.Log;
import android.widget.Button;
import org.kde.kdeconnect.Helpers.AppsHelper;
import org.kde.kdeconnect.Helpers.ImagesHelper;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect.UserInterface.DeviceActivity;
import org.kde.kdeconnect.UserInterface.SettingsActivity;
import org.kde.kdeconnect_tp.R;
import java.io.ByteArrayOutputStream;
public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener {
/*
private boolean sendIcons = false;
*/
@Override
public String getPluginName() {
return "plugin_notifications";
@@ -253,7 +249,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
np.set("silent", true);
np.set("requestAnswer", true); //For compatibility with old desktop versions of KDE Connect that don't support "silent"
}
/*
if (sendIcons) {
try {
Drawable drawableAppIcon = AppsHelper.appIconLookup(context, packageName);
@@ -270,7 +266,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
Log.e("NotificationsPlugin", "Error retrieving icon");
}
}
*/
np.set("id", id.serialize());
np.set("appName", appName == null? packageName : appName);
np.set("isClearable", statusBarNotification.isClearable());
@@ -329,11 +325,11 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
@Override
public boolean onPackageReceived(final NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_NOTIFICATION)) return false;
/*
if (np.getBoolean("sendIcons")) {
sendIcons = true;
}
*/
if (np.getBoolean("request")) {
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {

View File

@@ -144,56 +144,56 @@ public class ShareActivity extends ActionBarActivity {
Device device = devicesList.get(i-1); //NOTE: -1 because of the title!
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_STREAM)) {
if (extras != null) {
if (extras.containsKey(Intent.EXTRA_STREAM)) {
try {
try {
ArrayList<Uri> uriList;
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
ArrayList<Uri> uriList;
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
} else {
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
uriList = new ArrayList<Uri>();
uriList.add(uri);
}
queuedSendUriList(device, uriList);
} catch (Exception e) {
Log.e("ShareActivity", "Exception");
e.printStackTrace();
}
} else if (extras.containsKey(Intent.EXTRA_TEXT)) {
String text = extras.getString(Intent.EXTRA_TEXT);
String subject = extras.getString(Intent.EXTRA_SUBJECT);
//Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
if (subject != null && subject.endsWith("YouTube")) {
int index = text.indexOf(": http://youtu.be/");
if (index > 0) {
text = text.substring(index + 2); //Skip ": "
}
}
boolean isUrl;
try {
new URL(text);
isUrl = true;
} catch (Exception e) {
isUrl = false;
}
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
if (isUrl) {
np.set("url", text);
} else {
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
uriList = new ArrayList<Uri>();
uriList.add(uri);
np.set("text", text);
}
queuedSendUriList(device, uriList);
} catch (Exception e) {
Log.e("ShareActivity", "Exception");
e.printStackTrace();
device.sendPackage(np);
}
} else if (extras.containsKey(Intent.EXTRA_TEXT)) {
String text = extras.getString(Intent.EXTRA_TEXT);
String subject = extras.getString(Intent.EXTRA_SUBJECT);
//Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
if (subject != null && subject.endsWith("YouTube")) {
int index = text.indexOf(": http://youtu.be/");
if (index > 0) {
text = text.substring(index+2); //Skip ": "
}
}
boolean isUrl;
try {
new URL(text);
isUrl = true;
} catch(Exception e) {
isUrl = false;
}
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
if (isUrl) {
np.set("url", text);
} else {
np.set("text", text);
}
device.sendPackage(np);
}
finish();
}
});
@@ -235,12 +235,13 @@ public class ShareActivity extends ActionBarActivity {
try {
size = new File(uri.getPath()).length();
np.setPayload(inputStream, size);
} catch(Exception e) {
Log.e("ShareActivity", "Could not obtain file size");
e.printStackTrace();
}
np.setPayload(inputStream, size);
}else{
// Probably a content:// uri, so we query the Media content provider

View File

@@ -141,8 +141,10 @@ public class SharePlugin extends Plugin {
new Thread(new Runnable() {
@Override
public void run() {
OutputStream output = null;
boolean successul = true;
try {
OutputStream output = new FileOutputStream(destinationFullPath.getPath());
output = new FileOutputStream(destinationFullPath.getPath());
byte data[] = new byte[1024];
long progress = 0, prevProgressPercentage = 0;
int count;
@@ -162,9 +164,17 @@ public class SharePlugin extends Plugin {
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
successul = false;
Log.e("SharePlugin", "Receiver thread exception");
e.printStackTrace();
} finally {
try { output.close(); } catch (Exception e) {}
try { input.close(); } catch (Exception e) {}
}
try {
Log.i("SharePlugin", "Transfer finished");
//Make sure it is added to the Android Gallery
@@ -185,23 +195,25 @@ public class SharePlugin extends Plugin {
Resources res = context.getResources();
String message = successul? res.getString(R.string.received_file_title, device.getName()) : res.getString(R.string.received_file_fail_title, device.getName());
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(res.getString(R.string.received_file_title, device.getName()))
.setContentText(res.getString(R.string.received_file_text, filename))
.setContentIntent(resultPendingIntent)
.setTicker(res.getString(R.string.received_file_title, device.getName()))
.setContentTitle(message)
.setTicker(message)
.setSmallIcon(android.R.drawable.stat_sys_download_done)
.setAutoCancel(true);
if (successul) {
builder.setContentText(res.getString(R.string.received_file_text, filename))
.setContentIntent(resultPendingIntent);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getBoolean("share_notification_preference", true)) {
builder.setDefaults(Notification.DEFAULT_ALL);
}
Notification noti = builder.build();
notificationManager.notify(notificationId, noti);
Notification notification = builder.build();
notificationManager.notify(notificationId, notification);
} catch (Exception e) {
Log.e("SharePlugin", "Receiver thread exception");

View File

@@ -207,6 +207,7 @@ public class TelephonyPlugin extends Plugin {
public boolean onCreate() {
//Log.e("TelephonyPlugin", "onCreate");
IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
filter.setPriority(500);
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
context.registerReceiver(receiver, filter);
return true;

View File

@@ -108,8 +108,11 @@ public class CustomDevicesActivity extends ListActivity {
InputMethodManager inputManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
View focus = getCurrentFocus();
if (focus != null) {
inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
void saveList() {

View File

@@ -46,10 +46,12 @@ public class SmallEntryItem implements ListAdapter.Item {
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
TextView titleView = (TextView)v.findViewById(android.R.id.text1);
if (titleView != null) titleView.setText(title);
if (clickListener != null) {
titleView.setOnClickListener(clickListener);
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
if (titleView != null) {
titleView.setText(title);
if (clickListener != null) {
titleView.setOnClickListener(clickListener);
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
}
}
return v;

View File

@@ -45,10 +45,6 @@ import java.util.Collection;
public class MainActivity extends ActionBarActivity {
//
// Action bar
//
private MenuItem menuProgress;
@Override

View File

@@ -61,7 +61,7 @@ public class MainSettingsActivity extends PreferenceActivity {
}
private void initPreferences(final EditTextPreference deviceNamePref) {
final SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
deviceNamePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newDeviceName) {
@@ -99,16 +99,12 @@ public class MainSettingsActivity extends PreferenceActivity {
* @param context the application context
*/
public static void initializeDeviceName(Context context){
// I could have used getDefaultSharedPreferences(context).contains but we need to check
// to checkAgainst empty String also.
String deviceName=PreferenceManager.getDefaultSharedPreferences(context).getString(
KEY_DEVICE_NAME_PREFERENCE,
"");
if(deviceName.isEmpty()){
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
// Could use prefrences.contains but would need to check for empty String anyway.
String deviceName = preferences.getString(KEY_DEVICE_NAME_PREFERENCE, "");
if (deviceName.isEmpty()){
Log.i("MainSettingsActivity", "New device name: " + deviceName);
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
KEY_DEVICE_NAME_PREFERENCE,
DeviceHelper.getDeviceName()).commit();
preferences.edit().putString(KEY_DEVICE_NAME_PREFERENCE, DeviceHelper.getDeviceName()).commit();
}
}