2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

Refactor capabilities together with Aleix

He is committing a similar patch to kdeconnect-kde
This commit is contained in:
Albert Vaca
2016-05-31 17:19:39 +02:00
parent 108f9e911d
commit d253fcfd0b
16 changed files with 139 additions and 115 deletions

View File

@@ -38,22 +38,10 @@ public class NetworkPackage {
public final static int ProtocolVersion = 6; public final static int ProtocolVersion = 6;
//TODO: Move these to their respective plugins
public final static String PACKAGE_TYPE_IDENTITY = "kdeconnect.identity"; public final static String PACKAGE_TYPE_IDENTITY = "kdeconnect.identity";
public final static String PACKAGE_TYPE_PAIR = "kdeconnect.pair"; public final static String PACKAGE_TYPE_PAIR = "kdeconnect.pair";
public final static String PACKAGE_TYPE_ENCRYPTED = "kdeconnect.encrypted"; public final static String PACKAGE_TYPE_ENCRYPTED = "kdeconnect.encrypted";
public final static String PACKAGE_TYPE_PING = "kdeconnect.ping";
public final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
public final static String PACKAGE_TYPE_BATTERY = "kdeconnect.battery";
public final static String PACKAGE_TYPE_SFTP = "kdeconnect.sftp";
public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
public final static String PACKAGE_TYPE_MOUSEPAD = "kdeconnect.mousepad";
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
public static final String PACKAGE_TYPE_CAPABILITIES = "kdeconnect.capabilities"; public static final String PACKAGE_TYPE_CAPABILITIES = "kdeconnect.capabilities";
public final static String PACKAGE_TYPE_FINDMYPHONE = "kdeconnect.findmyphone" ;
public final static String PACKAGE_TYPE_RUNCOMMAND = "kdeconnect.runcommand";
private long mId; private long mId;
private String mType; private String mType;

View File

@@ -33,6 +33,9 @@ import org.kde.kdeconnect_tp.R;
public class BatteryPlugin extends Plugin { public class BatteryPlugin extends Plugin {
public final static String PACKAGE_TYPE_BATTERY = "kdeconnect.battery";
public final static String PACKAGE_TYPE_BATTERY_REQUEST = "kdeconnect.battery.request";
// keep these fields in sync with kdeconnect-kded:BatteryPlugin.h:ThresholdBatteryEvent // keep these fields in sync with kdeconnect-kded:BatteryPlugin.h:ThresholdBatteryEvent
private static final int THRESHOLD_EVENT_NONE= 0; private static final int THRESHOLD_EVENT_NONE= 0;
private static final int THRESHOLD_EVENT_BATTERY_LOW = 1; private static final int THRESHOLD_EVENT_BATTERY_LOW = 1;
@@ -72,7 +75,7 @@ public class BatteryPlugin extends Plugin {
} else { } else {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_BATTERY); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_BATTERY);
np.set("currentCharge", currentCharge); np.set("currentCharge", currentCharge);
np.set("isCharging", isCharging); np.set("isCharging", isCharging);
np.set("thresholdEvent", thresholdEvent); np.set("thresholdEvent", thresholdEvent);
@@ -99,7 +102,7 @@ public class BatteryPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_BATTERY)) return false; if (!np.getType().equals(PACKAGE_TYPE_BATTERY_REQUEST)) return false;
if (np.getBoolean("request")) { if (np.getBoolean("request")) {
if (lastInfo != null) { if (lastInfo != null) {
@@ -112,13 +115,13 @@ public class BatteryPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_BATTERY}; String[] packetTypes = {PACKAGE_TYPE_BATTERY_REQUEST};
return packetTypes; return packetTypes;
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_BATTERY}; String[] packetTypes = {PACKAGE_TYPE_BATTERY};
return packetTypes; return packetTypes;
} }

View File

@@ -60,7 +60,7 @@ public class ClipboardListener {
String content = item.coerceToText(context).toString(); String content = item.coerceToText(context).toString();
if (!content.equals(currentContent)) { if (!content.equals(currentContent)) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CLIPBOARD); NetworkPackage np = new NetworkPackage(ClipboardPlugin.PACKAGE_TYPE_CLIPBOARD);
np.set("content", content); np.set("content", content);
device.sendPackage(np); device.sendPackage(np);
currentContent = content; currentContent = content;

View File

@@ -32,6 +32,8 @@ import org.kde.kdeconnect_tp.R;
public class ClipboardPlugin extends Plugin { public class ClipboardPlugin extends Plugin {
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_clipboard); return context.getResources().getString(R.string.pref_plugin_clipboard);
@@ -63,7 +65,7 @@ public class ClipboardPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_CLIPBOARD)) { if (!np.getType().equals(PACKAGE_TYPE_CLIPBOARD)) {
return false; return false;
} }
@@ -74,13 +76,13 @@ public class ClipboardPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_CLIPBOARD}; String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD};
return packetTypes; return packetTypes;
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_CLIPBOARD}; String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD};
return packetTypes; return packetTypes;
} }

View File

@@ -17,6 +17,10 @@ import org.kde.kdeconnect_tp.R;
* and David Edmundson 2015 * and David Edmundson 2015
*/ */
public class FindMyPhonePlugin extends Plugin { public class FindMyPhonePlugin extends Plugin {
public final static String PACKAGE_TYPE_FINDMYPHONE = "kdeconnect.findmyphone";
public final static String PACKAGE_TYPE_FINDMYPHONE_REQUEST = "kdeconnect.findmyphone.request";
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return context.getString(R.string.findmyphone_title); return context.getString(R.string.findmyphone_title);
@@ -29,7 +33,7 @@ public class FindMyPhonePlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_FINDMYPHONE)) { if (np.getType().equals(PACKAGE_TYPE_FINDMYPHONE_REQUEST)) {
//Log.e("PingPackageReceiver", "was a find my phone!"); //Log.e("PingPackageReceiver", "was a find my phone!");
Intent intent = new Intent(context,FindMyPhoneActivity.class); Intent intent = new Intent(context,FindMyPhoneActivity.class);
@@ -43,7 +47,7 @@ public class FindMyPhonePlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_FINDMYPHONE}; return new String[]{PACKAGE_TYPE_FINDMYPHONE_REQUEST};
} }
@Override @Override

View File

@@ -101,7 +101,7 @@ public class KeyListenerView extends View {
} }
public void sendChars(CharSequence chars) { public void sendChars(CharSequence chars) {
final NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_INPUT);
np.set("key", chars.toString()); np.set("key", chars.toString());
sendKeyPressPackage(np); sendKeyPressPackage(np);
} }
@@ -135,7 +135,7 @@ public class KeyListenerView extends View {
//Log.e("KeyDown", "utfChar:" + (char)event.getUnicodeChar()); //Log.e("KeyDown", "utfChar:" + (char)event.getUnicodeChar());
//Log.e("KeyDown", "intUtfChar:" + event.getUnicodeChar()); //Log.e("KeyDown", "intUtfChar:" + event.getUnicodeChar());
final NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_INPUT);
boolean modifier = false; boolean modifier = false;
if (event.isAltPressed()) { if (event.isAltPressed()) {

View File

@@ -31,6 +31,9 @@ import org.kde.kdeconnect_tp.R;
public class MousePadPlugin extends Plugin { public class MousePadPlugin extends Plugin {
public final static String PACKAGE_TYPE_INPUT = "kdeconnect.input";
public final static String PACKAGE_TYPE_INPUT_REQUEST = "kdeconnect.input.request";
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return context.getString(R.string.pref_plugin_mousepad); return context.getString(R.string.pref_plugin_mousepad);
@@ -70,7 +73,7 @@ public class MousePadPlugin extends Plugin {
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_MOUSEPAD}; return new String[]{PACKAGE_TYPE_INPUT_REQUEST};
} }
@Override @Override
@@ -79,7 +82,7 @@ public class MousePadPlugin extends Plugin {
} }
public void sendMouseDelta(float dx, float dy, float sensitivity) { public void sendMouseDelta(float dx, float dy, float sensitivity) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("dx", dx*sensitivity); np.set("dx", dx*sensitivity);
np.set("dy", dy*sensitivity); np.set("dy", dy*sensitivity);
@@ -88,37 +91,37 @@ public class MousePadPlugin extends Plugin {
} }
public void sendSingleClick() { public void sendSingleClick() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("singleclick", true); np.set("singleclick", true);
device.sendPackage(np); device.sendPackage(np);
} }
public void sendDoubleClick() { public void sendDoubleClick() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("doubleclick", true); np.set("doubleclick", true);
device.sendPackage(np); device.sendPackage(np);
} }
public void sendMiddleClick() { public void sendMiddleClick() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("middleclick", true); np.set("middleclick", true);
device.sendPackage(np); device.sendPackage(np);
} }
public void sendRightClick() { public void sendRightClick() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("rightclick", true); np.set("rightclick", true);
device.sendPackage(np); device.sendPackage(np);
} }
public void sendSingleHold(){ public void sendSingleHold(){
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("singlehold", true); np.set("singlehold", true);
device.sendPackage(np); device.sendPackage(np);
} }
public void sendScroll(float dx, float dy) { public void sendScroll(float dx, float dy) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
np.set("scroll", true); np.set("scroll", true);
np.set("dx", dx); np.set("dx", dx);
np.set("dy", dy); np.set("dy", dy);

View File

@@ -37,6 +37,9 @@ import java.util.HashMap;
public class MprisPlugin extends Plugin { public class MprisPlugin extends Plugin {
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
public final static String PACKAGE_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request";
private String player = ""; private String player = "";
private boolean playing = false; private boolean playing = false;
private String currentSong = ""; private String currentSong = "";
@@ -82,7 +85,7 @@ public class MprisPlugin extends Plugin {
} }
public void sendAction(String player, String action) { public void sendAction(String player, String action) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", player); np.set("player", player);
np.set("action", action); np.set("action", action);
device.sendPackage(np); device.sendPackage(np);
@@ -92,14 +95,14 @@ public class MprisPlugin extends Plugin {
} }
public void setVolume(int volume) { public void setVolume(int volume) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", player); np.set("player", player);
np.set("setVolume",volume); np.set("setVolume",volume);
device.sendPackage(np); device.sendPackage(np);
} }
public void setPosition(int position) { public void setPosition(int position) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", player); np.set("player", player);
np.set("SetPosition", position); np.set("SetPosition", position);
device.sendPackage(np); device.sendPackage(np);
@@ -108,7 +111,7 @@ public class MprisPlugin extends Plugin {
} }
public void Seek(int offset) { public void Seek(int offset) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", player); np.set("player", player);
np.set("Seek", offset); np.set("Seek", offset);
device.sendPackage(np); device.sendPackage(np);
@@ -116,7 +119,7 @@ public class MprisPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_MPRIS)) return false; if (!np.getType().equals(PACKAGE_TYPE_MPRIS)) return false;
if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") || np.has("pos")) { if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") || np.has("pos")) {
if (np.getString("player").equals(player)) { if (np.getString("player").equals(player)) {
@@ -172,12 +175,12 @@ public class MprisPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[] {NetworkPackage.PACKAGE_TYPE_MPRIS}; return new String[] {PACKAGE_TYPE_MPRIS};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[] {NetworkPackage.PACKAGE_TYPE_MPRIS}; return new String[] {PACKAGE_TYPE_MPRIS_REQUEST};
} }
public void setPlayerStatusUpdatedHandler(String id, Handler h) { public void setPlayerStatusUpdatedHandler(String id, Handler h) {
@@ -251,13 +254,13 @@ public class MprisPlugin extends Plugin {
} }
private void requestPlayerList() { private void requestPlayerList() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("requestPlayerList",true); np.set("requestPlayerList",true);
device.sendPackage(np); device.sendPackage(np);
} }
private void requestPlayerStatus() { private void requestPlayerStatus() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player",player); np.set("player",player);
np.set("requestNowPlaying",true); np.set("requestNowPlaying",true);
np.set("requestVolume",true); np.set("requestVolume",true);

View File

@@ -50,6 +50,10 @@ import java.io.InputStream;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener { public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener {
public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
public final static String PACKAGE_TYPE_NOTIFICATION_REQUEST = "kdeconnect.notification.request";
/* /*
private boolean sendIcons = false; private boolean sendIcons = false;
*/ */
@@ -109,7 +113,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
} }
// request all existing notifications // request all existing notifications
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION_REQUEST);
np.set("request", true); np.set("request", true);
device.sendPackage(np); device.sendPackage(np);
return true; return true;
@@ -131,7 +135,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
@Override @Override
public void onNotificationRemoved(StatusBarNotification statusBarNotification) { public void onNotificationRemoved(StatusBarNotification statusBarNotification) {
String id = getNotificationKeyCompat(statusBarNotification); String id = getNotificationKeyCompat(statusBarNotification);
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION_REQUEST);
np.set("id", id); np.set("id", id);
np.set("isCancel", true); np.set("isCancel", true);
device.sendPackage(np); device.sendPackage(np);
@@ -185,7 +189,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return; return;
} }
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION);
if (packageName.equals("org.kde.kdeconnect_tp")) if (packageName.equals("org.kde.kdeconnect_tp"))
{ {
@@ -268,7 +272,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
@Override @Override
public boolean onPackageReceived(final NetworkPackage np) { public boolean onPackageReceived(final NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_NOTIFICATION)) return false; if (!np.getType().equals(PACKAGE_TYPE_NOTIFICATION_REQUEST) && !np.getType().equals(PACKAGE_TYPE_NOTIFICATION)) return false;
/* /*
if (np.getBoolean("sendIcons")) { if (np.getBoolean("sendIcons")) {
sendIcons = true; sendIcons = true;
@@ -416,12 +420,12 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_NOTIFICATION}; return new String[]{PACKAGE_TYPE_NOTIFICATION, PACKAGE_TYPE_NOTIFICATION_REQUEST};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_NOTIFICATION}; return new String[]{PACKAGE_TYPE_NOTIFICATION, PACKAGE_TYPE_NOTIFICATION_REQUEST};
} }
//For compat with API<21, because lollipop changed the way to cancel notifications //For compat with API<21, because lollipop changed the way to cancel notifications

View File

@@ -37,6 +37,8 @@ import org.kde.kdeconnect_tp.R;
public class PingPlugin extends Plugin { public class PingPlugin extends Plugin {
public final static String PACKAGE_TYPE_PING = "kdeconnect.ping";
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_ping); return context.getResources().getString(R.string.pref_plugin_ping);
@@ -50,50 +52,50 @@ public class PingPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
//Log.e("PingPackageReceiver", "onPackageReceived"); if (!np.getType().equals(PACKAGE_TYPE_PING)) {
if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_PING)) { return false;
//Log.e("PingPackageReceiver", "was a ping!");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MaterialActivity.class);
stackBuilder.addNextIntent(new Intent(context, MaterialActivity.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();
} else {
message = "Ping!";
id = 42; //A unique id to create only one notification
}
Notification noti = new NotificationCompat.Builder(context)
.setContentTitle(device.getName())
.setContentText(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);
try {
notificationManager.notify(id, noti);
} catch(Exception e) {
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
}
return true;
} }
return false;
//Log.e("PingPackageReceiver", "was a ping!");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MaterialActivity.class);
stackBuilder.addNextIntent(new Intent(context, MaterialActivity.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();
} else {
message = "Ping!";
id = 42; //A unique id to create only one notification
}
Notification noti = new NotificationCompat.Builder(context)
.setContentTitle(device.getName())
.setContentText(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);
try {
notificationManager.notify(id, noti);
} catch(Exception e) {
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
}
return true;
} }
@Override @Override
@@ -104,7 +106,7 @@ public class PingPlugin extends Plugin {
@Override @Override
public void startMainActivity(Activity activity) { public void startMainActivity(Activity activity) {
if (device != null) { if (device != null) {
device.sendPackage(new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PING)); device.sendPackage(new NetworkPackage(PACKAGE_TYPE_PING));
} }
} }
@@ -120,12 +122,12 @@ public class PingPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_PING}; return new String[]{PACKAGE_TYPE_PING};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_PING}; return new String[]{PACKAGE_TYPE_PING};
} }
} }

View File

@@ -37,6 +37,9 @@ import java.util.Iterator;
public class RunCommandPlugin extends Plugin { public class RunCommandPlugin extends Plugin {
public final static String PACKAGE_TYPE_RUNCOMMAND = "kdeconnect.runcommand";
public final static String PACKAGE_TYPE_RUNCOMMAND_REQUEST = "kdeconnect.runcommand.request";
private ArrayList<JSONObject> commandList = new ArrayList<>(); private ArrayList<JSONObject> commandList = new ArrayList<>();
private ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>(); private ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>();
@@ -79,7 +82,7 @@ public class RunCommandPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_RUNCOMMAND)) return false; if (!np.getType().equals(PACKAGE_TYPE_RUNCOMMAND)) return false;
if (np.has("commandList")) { if (np.has("commandList")) {
commandList.clear(); commandList.clear();
@@ -109,22 +112,22 @@ public class RunCommandPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_RUNCOMMAND}; return new String[]{PACKAGE_TYPE_RUNCOMMAND};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_RUNCOMMAND}; return new String[]{PACKAGE_TYPE_RUNCOMMAND_REQUEST};
} }
public void runCommand(String cmdKey) { public void runCommand(String cmdKey) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_RUNCOMMAND); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_RUNCOMMAND_REQUEST);
np.set("key", cmdKey); np.set("key", cmdKey);
device.sendPackage(np); device.sendPackage(np);
} }
private void requestCommandList() { private void requestCommandList() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_RUNCOMMAND); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_RUNCOMMAND_REQUEST);
np.set("requestCommandList", true); np.set("requestCommandList", true);
device.sendPackage(np); device.sendPackage(np);
} }

View File

@@ -33,6 +33,9 @@ import java.util.List;
public class SftpPlugin extends Plugin { public class SftpPlugin extends Plugin {
public final static String PACKAGE_TYPE_SFTP = "kdeconnect.sftp";
public final static String PACKAGE_TYPE_SFTP_REQUEST = "kdeconnect.sftp.request";
private static final SimpleSftpServer server = new SimpleSftpServer(); private static final SimpleSftpServer server = new SimpleSftpServer();
@Override @Override
@@ -58,12 +61,12 @@ public class SftpPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_SFTP)) return false; if (!np.getType().equals(PACKAGE_TYPE_SFTP_REQUEST)) return false;
if (np.getBoolean("startBrowsing")) { if (np.getBoolean("startBrowsing")) {
if (server.start()) { if (server.start()) {
NetworkPackage np2 = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SFTP); NetworkPackage np2 = new NetworkPackage(PACKAGE_TYPE_SFTP);
np2.set("ip", server.getLocalIpAddress()); np2.set("ip", server.getLocalIpAddress());
np2.set("port", server.port); np2.set("port", server.port);
@@ -129,12 +132,12 @@ public class SftpPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_SFTP}; return new String[]{PACKAGE_TYPE_SFTP_REQUEST};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_SFTP}; return new String[]{PACKAGE_TYPE_SFTP};
} }
} }

View File

@@ -170,7 +170,7 @@ public class ShareActivity extends ActionBarActivity {
} catch (Exception e) { } catch (Exception e) {
isUrl = false; isUrl = false;
} }
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE); NetworkPackage np = new NetworkPackage(SharePlugin.PACKAGE_TYPE_SHARE);
if (isUrl) { if (isUrl) {
np.set("url", text); np.set("url", text);
} else { } else {

View File

@@ -58,6 +58,9 @@ import java.util.ArrayList;
public class SharePlugin extends Plugin { public class SharePlugin extends Plugin {
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
public final static String PACKAGE_TYPE_SHARE_REQUEST = "kdeconnect.share.request";
final static boolean openUrlsDirectly = true; final static boolean openUrlsDirectly = true;
@Override @Override
@@ -100,7 +103,7 @@ public class SharePlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_SHARE)) { if (!np.getType().equals(PACKAGE_TYPE_SHARE_REQUEST)) {
return false; return false;
} }
@@ -311,7 +314,7 @@ public class SharePlugin extends Plugin {
ContentResolver cr = context.getContentResolver(); ContentResolver cr = context.getContentResolver();
InputStream inputStream = cr.openInputStream(uri); InputStream inputStream = cr.openInputStream(uri);
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_SHARE_REQUEST);
long size = -1; long size = -1;
final NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -496,12 +499,12 @@ public class SharePlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_SHARE}; return new String[]{PACKAGE_TYPE_SHARE_REQUEST};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_SHARE}; return new String[]{PACKAGE_TYPE_SHARE_REQUEST};
} }

View File

@@ -36,6 +36,9 @@ import static android.provider.ContactsContract.Contacts;
public class TelepathyPlugin extends Plugin { public class TelepathyPlugin extends Plugin {
public final static String PACKAGE_TYPE_SMS_REQUEST = "kdeconnect.sms";
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telepathy); return context.getResources().getString(R.string.pref_plugin_telepathy);
@@ -58,7 +61,7 @@ public class TelepathyPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_TELEPHONY)) { if (!np.getType().equals(PACKAGE_TYPE_SMS_REQUEST)) {
return false; return false;
} }
@@ -171,12 +174,12 @@ public class TelepathyPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY}; return new String[]{PACKAGE_TYPE_SMS_REQUEST};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY}; return new String[]{};
} }
} }

View File

@@ -40,6 +40,9 @@ import java.util.TimerTask;
public class TelephonyPlugin extends Plugin { public class TelephonyPlugin extends Plugin {
public final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
public final static String PACKAGE_TYPE_TELEPHONY_REQUEST = "kdeconnect.telephony.request";
private int lastState = TelephonyManager.CALL_STATE_IDLE; private int lastState = TelephonyManager.CALL_STATE_IDLE;
private NetworkPackage lastPackage = null; private NetworkPackage lastPackage = null;
private boolean isMuted = false; private boolean isMuted = false;
@@ -97,7 +100,7 @@ public class TelephonyPlugin extends Plugin {
//Log.e("TelephonyPlugin", "callBroadcastReceived"); //Log.e("TelephonyPlugin", "callBroadcastReceived");
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
if (phoneNumber != null) { if (phoneNumber != null) {
np.set("phoneNumber", phoneNumber); np.set("phoneNumber", phoneNumber);
np.set("contactName", ContactsHelper.phoneNumberLookup(context, phoneNumber)); np.set("contactName", ContactsHelper.phoneNumberLookup(context, phoneNumber));
@@ -163,7 +166,7 @@ public class TelephonyPlugin extends Plugin {
//Log.e("SmsBroadcastReceived", message.toString()); //Log.e("SmsBroadcastReceived", message.toString());
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY); NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
np.set("event","sms"); np.set("event","sms");
@@ -198,7 +201,7 @@ public class TelephonyPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_TELEPHONY)) { if (!np.getType().equals(PACKAGE_TYPE_TELEPHONY_REQUEST)) {
return false; return false;
} }
if (np.getString("action").equals("mute")) { if (np.getString("action").equals("mute")) {
@@ -215,12 +218,12 @@ public class TelephonyPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY}; return new String[]{PACKAGE_TYPE_TELEPHONY_REQUEST};
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY}; return new String[]{PACKAGE_TYPE_TELEPHONY};
} }
} }