2013-09-05 01:37:59 +02:00
|
|
|
package org.kde.kdeconnect;
|
2013-06-19 16:15:25 +02:00
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2013-07-24 23:51:06 +02:00
|
|
|
import android.net.ConnectivityManager;
|
2013-06-19 16:15:25 +02:00
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2013-08-16 10:31:01 +02:00
|
|
|
public class KdeConnectBroadcastReceiver extends BroadcastReceiver
|
2013-06-19 16:15:25 +02:00
|
|
|
{
|
2013-08-10 05:16:59 +02:00
|
|
|
|
2013-08-16 10:31:01 +02:00
|
|
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2013-06-19 16:15:25 +02:00
|
|
|
|
2013-09-05 10:48:42 +02:00
|
|
|
//Log.e("KdeConnect", "Broadcast event: "+intent.getAction());
|
2013-06-19 16:15:25 +02:00
|
|
|
|
|
|
|
String action = intent.getAction();
|
2013-08-16 10:31:01 +02:00
|
|
|
|
2013-06-19 16:15:25 +02:00
|
|
|
if(action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("KdeConnect", "UpdateReceiver");
|
2013-06-19 16:15:25 +02:00
|
|
|
if (!intent.getData().getSchemeSpecificPart().equals(context.getPackageName())) {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("KdeConnect", "Ignoring, it's not me!");
|
2013-06-19 16:15:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-07-04 19:17:22 +02:00
|
|
|
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
2013-07-23 16:11:54 +02:00
|
|
|
|
2013-07-04 19:17:22 +02:00
|
|
|
}
|
|
|
|
});
|
2013-06-19 16:15:25 +02:00
|
|
|
} else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("KdeConnect", "KdeConnectBroadcastReceiver");
|
2013-07-04 19:17:22 +02:00
|
|
|
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
2013-07-23 16:11:54 +02:00
|
|
|
|
2013-07-04 19:17:22 +02:00
|
|
|
}
|
|
|
|
});
|
2013-07-23 16:11:54 +02:00
|
|
|
} else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)
|
2013-07-24 23:51:06 +02:00
|
|
|
|| action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)
|
|
|
|
|| action.equals(ConnectivityManager.CONNECTIVITY_ACTION)
|
|
|
|
) {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("KdeConnect", "Connection state changed, trying to connect");
|
2013-07-02 15:22:05 +02:00
|
|
|
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
2013-08-07 10:44:52 +02:00
|
|
|
service.onNetworkChange();
|
2013-07-02 15:22:05 +02:00
|
|
|
}
|
|
|
|
});
|
2013-08-10 05:16:59 +02:00
|
|
|
} else if (action.equals(Intent.ACTION_SCREEN_ON)) {
|
|
|
|
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
|
|
|
@Override
|
|
|
|
public void onServiceStart(BackgroundService service) {
|
|
|
|
service.onNetworkChange();
|
|
|
|
}
|
|
|
|
});
|
2013-06-19 16:15:25 +02:00
|
|
|
} else {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("KdeConnectBroadcastReceiver", "Ignoring broadcast event: "+intent.getAction());
|
2013-06-19 16:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-08-16 10:31:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-19 16:15:25 +02:00
|
|
|
}
|