mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 13:17:43 +00:00
KdeService was not compiling
This commit is contained in:
parent
dd2a545e0d
commit
c02b1e3af4
@ -1,18 +0,0 @@
|
||||
package org.kde.connect;
|
||||
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
|
||||
/**
|
||||
* Created by vaka on 6/10/13.
|
||||
*/
|
||||
public interface Announcer {
|
||||
|
||||
public interface ConnexionReceiver {
|
||||
public void onPair(ComputerLink p);
|
||||
}
|
||||
|
||||
public boolean startAnnouncing(ConnexionReceiver cr);
|
||||
|
||||
public void stopAnnouncing();
|
||||
|
||||
}
|
@ -1,21 +1,17 @@
|
||||
package org.kde.connect;
|
||||
package org.kde.connect.Announcers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.nsd.NsdManager;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.connect.Announcer;
|
||||
import org.kde.connect.ComputerLink;
|
||||
import org.kde.connect.ComputerLinks.BaseComputerLink;
|
||||
import org.kde.connect.ComputerLinks.UdpComputerLink;
|
||||
import org.kde.connect.Types.NetworkPackage;
|
||||
import org.kde.connect.UdpComputerLink;
|
||||
|
||||
import java.lang.Override;
|
||||
|
||||
/**
|
||||
* Created by vaka on 6/10/13.
|
||||
*/
|
||||
public class AvahiAnnouncer implements Announcer {
|
||||
public class AvahiAnnouncer extends BaseAnnouncer {
|
||||
|
||||
UdpComputerLink computerLink;
|
||||
|
||||
@ -52,16 +48,19 @@ public class AvahiAnnouncer implements Announcer {
|
||||
}
|
||||
};
|
||||
|
||||
ComputerLink.PackageReceiver mPackageReceiver = new ComputerLink.PackageReceiver() {
|
||||
BaseComputerLink.PackageReceiver mPackageReceiver = new BaseComputerLink.PackageReceiver() {
|
||||
@Override
|
||||
public void onPackageReceived(NetworkPackage np) {
|
||||
Log.e("Avahi announcer","packageReceived");
|
||||
connexionReceiver.onPair(new UdpComputerLink());
|
||||
/*
|
||||
if (np.getType() == NetworkPackage.Type.ID_REQUEST) {
|
||||
Log.i("Avahi announcer","ID_REQUEST");
|
||||
} else if (np.getType() == NetworkPackage.Type.PAIR_REQUEST) {
|
||||
Log.i("Avahi announcer","PAIR_REQUEST");
|
||||
} else {
|
||||
Log.i("Avahi announcer","Not paired, ignoring package "+np.getType());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
};
|
||||
|
||||
@ -84,6 +83,7 @@ public class AvahiAnnouncer implements Announcer {
|
||||
|
||||
@Override
|
||||
public boolean startAnnouncing(ConnexionReceiver cr) {
|
||||
super.startAnnouncing(cr);
|
||||
Log.i("AvahiAnnouncer","startAnnouncing");
|
||||
mNsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);
|
||||
computerLink.addPackageReceiver(mPackageReceiver);
|
||||
@ -92,6 +92,7 @@ public class AvahiAnnouncer implements Announcer {
|
||||
|
||||
@Override
|
||||
public void stopAnnouncing() {
|
||||
super.stopAnnouncing();
|
||||
mNsdManager.unregisterService(mRegistrationListener);
|
||||
computerLink.removePackageReceiver(mPackageReceiver);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.kde.connect.Announcers;
|
||||
|
||||
import org.kde.connect.ComputerLinks.BaseComputerLink;
|
||||
|
||||
public class BaseAnnouncer {
|
||||
|
||||
public interface ConnexionReceiver {
|
||||
public void onPair(BaseComputerLink p);
|
||||
}
|
||||
|
||||
protected ConnexionReceiver connexionReceiver;
|
||||
|
||||
//To override
|
||||
public boolean startAnnouncing(ConnexionReceiver cr) {
|
||||
connexionReceiver = cr;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void stopAnnouncing() {
|
||||
connexionReceiver = null;
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,9 @@ import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.connect.Announcers.BaseAnnouncer;
|
||||
import org.kde.connect.Announcers.AvahiAnnouncer;
|
||||
import org.kde.connect.ComputerLinks.BaseComputerLink;
|
||||
import org.kde.connect.PackageEmitters.BasePackageEmitter;
|
||||
import org.kde.connect.PackageEmitters.CallPackageEmitter;
|
||||
import org.kde.connect.PackageEmitters.PingPackageEmitter;
|
||||
@ -19,18 +22,22 @@ import java.util.ArrayList;
|
||||
public class BackgroundService extends Service {
|
||||
|
||||
SharedPreferences settings;
|
||||
ArrayList<Announcer> announcers = new ArrayList<Announcer>();
|
||||
ArrayList<ComputerLink> computerLinks = new ArrayList<ComputerLink>();
|
||||
|
||||
ArrayList<BaseAnnouncer> mBaseAnnouncers = new ArrayList<BaseAnnouncer>();
|
||||
ArrayList<BaseComputerLink> mBaseComputerLinks = new ArrayList<BaseComputerLink>();
|
||||
|
||||
ArrayList<BasePackageEmitter> emitters = new ArrayList<BasePackageEmitter>();
|
||||
ArrayList<BasePackageReceiver> receivers = new ArrayList<BasePackageReceiver>();
|
||||
|
||||
PingPackageEmitter pingEmitter;
|
||||
|
||||
private void addComputerLink(ComputerLink cl) {
|
||||
private void addComputerLink(BaseComputerLink cl) {
|
||||
|
||||
computerLinks.add(cl);
|
||||
Log.i("BackgroundService","addComputerLink");
|
||||
|
||||
mBaseComputerLinks.add(cl);
|
||||
|
||||
Log.i("BackgroundService","sending ping after connection");
|
||||
|
||||
NetworkPackage p = new NetworkPackage(System.currentTimeMillis());
|
||||
p.setType(NetworkPackage.Type.PING);
|
||||
@ -43,7 +50,6 @@ public class BackgroundService extends Service {
|
||||
emitters.add(new CallPackageEmitter(getApplicationContext()));
|
||||
}
|
||||
|
||||
pingEmitter = new PingPackageEmitter(getApplicationContext());
|
||||
if (settings.getBoolean("emit_ping", true)) {
|
||||
emitters.add(pingEmitter);
|
||||
}
|
||||
@ -55,14 +61,20 @@ public class BackgroundService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerAnnouncers() {
|
||||
if (settings.getBoolean("announce_avahi", true)) {
|
||||
mBaseAnnouncers.add(new AvahiAnnouncer(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e("BackgroundService","Starting");
|
||||
|
||||
for (Announcer a : announcers) {
|
||||
a.startAnnouncing(new Announcer.ConnexionReceiver() {
|
||||
for (BaseAnnouncer a : mBaseAnnouncers) {
|
||||
a.startAnnouncing(new BaseAnnouncer.ConnexionReceiver() {
|
||||
@Override
|
||||
public void onPair(ComputerLink cl) {
|
||||
public void onPair(BaseComputerLink cl) {
|
||||
addComputerLink(cl);
|
||||
}
|
||||
});
|
||||
@ -79,12 +91,13 @@ public class BackgroundService extends Service {
|
||||
public void onCreate() {
|
||||
Log.e("BackgroundService","Creating");
|
||||
|
||||
registerEmitters();
|
||||
registerReceivers();
|
||||
|
||||
settings = getSharedPreferences("KdeConnect", 0);
|
||||
|
||||
announcers.add(new AvahiAnnouncer(this));
|
||||
pingEmitter = new PingPackageEmitter(getApplicationContext());
|
||||
|
||||
registerEmitters();
|
||||
registerReceivers();
|
||||
registerAnnouncers();
|
||||
|
||||
super.onCreate();
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package org.kde.connect;
|
||||
package org.kde.connect.ComputerLinks;
|
||||
|
||||
import org.kde.connect.Types.NetworkPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public abstract class ComputerLink {
|
||||
public abstract class BaseComputerLink {
|
||||
|
||||
public interface PackageReceiver {
|
||||
public void onPackageReceived(NetworkPackage np);
|
||||
@ -20,6 +20,7 @@ public abstract class ComputerLink {
|
||||
receivers.remove(pr);
|
||||
}
|
||||
|
||||
//Should be called from a background thread listening to packages
|
||||
protected void packageReceived(NetworkPackage np) {
|
||||
for(PackageReceiver pr : receivers) {
|
||||
pr.onPackageReceived(np);
|
||||
@ -28,8 +29,6 @@ public abstract class ComputerLink {
|
||||
|
||||
//TO OVERRIDE
|
||||
|
||||
//Should set up a listener that calls packageReceived(NetworkPackage)
|
||||
public abstract void startListening();
|
||||
|
||||
//Should be async
|
||||
public abstract void sendPackage(NetworkPackage np);
|
@ -1,6 +1,5 @@
|
||||
package org.kde.connect;
|
||||
package org.kde.connect.ComputerLinks;
|
||||
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
@ -10,28 +9,33 @@ import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import org.kde.connect.ComputerLink;
|
||||
|
||||
public class UdpComputerLink extends ComputerLink {
|
||||
public class UdpComputerLink extends BaseComputerLink {
|
||||
|
||||
final int UDP_PORT = 10601;
|
||||
final String IP = "192.168.1.48";
|
||||
final int BUFFER_SIZE = 5*1024;
|
||||
|
||||
@Override
|
||||
public void startListening() {
|
||||
try {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
DatagramSocket socket = new DatagramSocket(UDP_PORT);
|
||||
while(true){
|
||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length );
|
||||
socket.receive(packet);
|
||||
String s = new String(packet.getData(), 0, packet.getLength());
|
||||
packageReceived(NetworkPackage.fromString(s));
|
||||
public UdpComputerLink() {
|
||||
new AsyncTask<Void,Void,Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
try {
|
||||
Log.e("UdpComputerLink","Waiting for udp datagrams");
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
DatagramSocket socket = new DatagramSocket(UDP_PORT);
|
||||
while(true){
|
||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length );
|
||||
socket.receive(packet);
|
||||
String s = new String(packet.getData(), 0, packet.getLength());
|
||||
packageReceived(NetworkPackage.fromString(s));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
@ -7,6 +7,7 @@ import android.content.ServiceConnection;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@ -23,6 +24,7 @@ public class MainActivity extends Activity {
|
||||
findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.i("MainActivity", "Button1");
|
||||
|
||||
Intent serviceIntent = new Intent(MainActivity.this, BackgroundService.class);
|
||||
startService(serviceIntent);
|
||||
@ -43,6 +45,7 @@ public class MainActivity extends Activity {
|
||||
findViewById(R.id.button2).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.i("MainActivity","Button2");
|
||||
if (service != null) service.sendPing();
|
||||
}
|
||||
});
|
||||
|
@ -1,24 +1,24 @@
|
||||
package org.kde.connect.PackageEmitters;
|
||||
|
||||
import org.kde.connect.ComputerLink;
|
||||
import org.kde.connect.ComputerLinks.BaseComputerLink;
|
||||
import org.kde.connect.Types.NetworkPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BasePackageEmitter {
|
||||
|
||||
private ArrayList<ComputerLink> computerLinks = new ArrayList<ComputerLink>();
|
||||
private ArrayList<BaseComputerLink> mBaseComputerLinks = new ArrayList<BaseComputerLink>();
|
||||
|
||||
public void addComputerLink(ComputerLink cl) {
|
||||
computerLinks.add(cl);
|
||||
public void addComputerLink(BaseComputerLink cl) {
|
||||
mBaseComputerLinks.add(cl);
|
||||
}
|
||||
|
||||
protected int countLinkedComputers() {
|
||||
return computerLinks.size();
|
||||
return mBaseComputerLinks.size();
|
||||
}
|
||||
|
||||
protected void sendPackage(NetworkPackage np) {
|
||||
for(ComputerLink cl : computerLinks) {
|
||||
for(BaseComputerLink cl : mBaseComputerLinks) {
|
||||
cl.sendPackage(np);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.connect.ComputerLink;
|
||||
import org.kde.connect.Types.NetworkPackage;
|
||||
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
package org.kde.connect.PackageEmitters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.connect.ComputerLink;
|
||||
import org.kde.connect.Types.NetworkPackage;
|
||||
|
||||
|
||||
@ -17,7 +14,7 @@ public class PingPackageEmitter extends BasePackageEmitter {
|
||||
}
|
||||
|
||||
public void sendPing() {
|
||||
Log.i("PingPackageEmitter", "sendPing to "+countLinkedComputers());
|
||||
Log.e("PingPackageEmitter", "sendPing to "+countLinkedComputers());
|
||||
|
||||
NetworkPackage lastPackage = new NetworkPackage(System.currentTimeMillis());
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
package org.kde.connect.PackageReceivers;
|
||||
|
||||
import org.kde.connect.ComputerLink;
|
||||
import org.kde.connect.Types.NetworkPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface BasePackageReceiver {
|
||||
|
||||
public void receivePackage(NetworkPackage np);
|
||||
|
Loading…
x
Reference in New Issue
Block a user