2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-29 05:07:40 +00:00

KCM skeleton

This commit is contained in:
Albert Vaca 2013-06-19 16:15:25 +02:00
parent 8fcd9e50c9
commit 1692fb7e14
6 changed files with 62 additions and 38 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.kde.connect" package="org.kde.kdeconnect"
android:versionCode="1" android:versionCode="1"
android:versionName="1.0" > android:versionName="1.0" >
@ -27,14 +27,24 @@
<service <service
android:enabled="true" android:enabled="true"
android:name=".BackgroundService"> android:name="org.kde.connect.BackgroundService">
</service> </service>
<receiver android:name=".BootReceiver"> <receiver android:name="org.kde.connect.ServiceLauncher">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED"></action>
<data android:scheme="package" android:path="org.kde.kdeconnect" />
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver> </receiver>

View File

@ -11,7 +11,6 @@ import android.os.IBinder;
import android.util.Log; import android.util.Log;
import org.kde.connect.ComputerLinks.BaseComputerLink; import org.kde.connect.ComputerLinks.BaseComputerLink;
import org.kde.connect.Extensions.SingletonService;
import org.kde.connect.Locators.AvahiLocator; import org.kde.connect.Locators.AvahiLocator;
import org.kde.connect.Locators.BaseLocator; import org.kde.connect.Locators.BaseLocator;
import org.kde.connect.PackageEmitters.BasePackageEmitter; import org.kde.connect.PackageEmitters.BasePackageEmitter;
@ -23,7 +22,7 @@ import org.kde.connect.Types.NetworkPackage;
import java.util.ArrayList; import java.util.ArrayList;
public class BackgroundService extends SingletonService { public class BackgroundService extends Service {
SharedPreferences settings; SharedPreferences settings;
@ -89,9 +88,9 @@ public class BackgroundService extends SingletonService {
a.reachComputers(new BaseLocator.ConnectionReceiver() { a.reachComputers(new BaseLocator.ConnectionReceiver() {
@Override @Override
public void onConnectionAccepted(BaseComputerLink link) { public void onConnectionAccepted(BaseComputerLink link) {
Log.e("BackgroundService","Connection accepted!"); Log.e("BackgroundService","Connection accepted!");
//TODO: Check if there are other links available, and keep the best one //TODO: Check if there are other links available, and keep the best one
addComputerLink(link); addComputerLink(link);
} }
}); });
} }
@ -132,7 +131,6 @@ public class BackgroundService extends SingletonService {
//Singleton service auxiliars //Singleton service auxiliars
private class LocalBinder extends Binder { private class LocalBinder extends Binder {
public BackgroundService getInstance() { public BackgroundService getInstance() {
return BackgroundService.this; return BackgroundService.this;
@ -154,10 +152,11 @@ public class BackgroundService extends SingletonService {
Start(c,null); Start(c,null);
} }
public static void Start(Context c, ServiceStartCallback callback) { public static void Start(Context c, final ServiceStartCallback callback) {
if (instance != null) { if (instance != null) {
Log.e("SingletonService","Already started"); Log.e("SingletonService","Already started");
callback.onServiceStart(instance);
} }
Intent serviceIntent = new Intent(c, BackgroundService.class); Intent serviceIntent = new Intent(c, BackgroundService.class);

View File

@ -1,23 +0,0 @@
package org.kde.connect;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class BootReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
if (intent.getAction() != Intent.ACTION_BOOT_COMPLETED) {
Log.w("KdeConnect", "Received unexpected intent: " + intent);
} else {
Log.i("KdeConnect", "BootReceiver");
context.startService(new Intent(context,BackgroundService.class));
}
}
}

View File

@ -28,7 +28,7 @@ public class MainActivity extends Activity {
} }
}); });
findViewById(R.id.button2).setOnClickListener(new OnClickListener() { findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Log.i("MainActivity","Button2"); Log.i("MainActivity","Button2");
@ -36,7 +36,7 @@ public class MainActivity extends Activity {
} }
}); });
findViewById(R.id.button3).setOnClickListener(new OnClickListener() { findViewById(R.id.button2).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Log.i("MainActivity","Button3"); Log.i("MainActivity","Button3");

View File

@ -0,0 +1,39 @@
package org.kde.connect;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.util.Log;
public class ServiceLauncher extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
Log.e("KdeConnect", "Broadcast event: "+intent.getAction());
String action = intent.getAction();
if(action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
Log.e("KdeConnect", "UpdateReceiver");
if (!intent.getData().getSchemeSpecificPart().equals(context.getPackageName())) {
Log.e("KdeConnect", "Ignoring, it's not me!");
return;
}
BackgroundService.Start(context);
} else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.e("KdeConnect", "ServiceLauncher");
BackgroundService.Start(context);
} else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
Log.e("KdeConnect", "Connection state changed, trying to connect");
BackgroundService service = BackgroundService.GetInstance();
service.reachComputers();
} else {
Log.e("KdeConnect", "Ignoring broadcast event: "+intent.getAction());
}
}
}

View File

@ -9,8 +9,7 @@
tools:context=".MainActivity" tools:context=".MainActivity"
android:orientation="vertical"> android:orientation="vertical">
<Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Phone boot (launch service)"/> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Start pairing"/>
<Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Connectivity change (try to reach computers)"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Send ping to connected computers"/>
<Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Send ping to connected computers"/>
</LinearLayout> </LinearLayout>