use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class NotificationsPlugin method onNotificationRemoved.
@Override
public void onNotificationRemoved(StatusBarNotification statusBarNotification) {
if (statusBarNotification == null) {
Log.w(TAG, "onNotificationRemoved: notification is null");
return;
}
String id = getNotificationKeyCompat(statusBarNotification);
actions.remove(id);
NetworkPacket np = new NetworkPacket(PACKET_TYPE_NOTIFICATION);
np.set("id", id);
np.set("isCancel", true);
device.sendPacket(np);
currentNotifications.remove(id);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class TelephonyPlugin method callBroadcastReceived.
private void callBroadcastReceived(int state, String phoneNumber) {
if (isNumberBlocked(phoneNumber))
return;
NetworkPacket np = new NetworkPacket(PACKET_TYPE_TELEPHONY);
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
Map<String, String> contactInfo = ContactsHelper.phoneNumberLookup(context, phoneNumber);
if (contactInfo.containsKey("name")) {
np.set("contactName", contactInfo.get("name"));
}
if (contactInfo.containsKey("photoID")) {
String photoUri = contactInfo.get("photoID");
if (photoUri != null) {
try {
String base64photo = ContactsHelper.photoId64Encoded(context, photoUri);
if (!TextUtils.isEmpty(base64photo)) {
np.set("phoneThumbnail", base64photo);
}
} catch (Exception e) {
Log.e("TelephonyPlugin", "Failed to get contact photo");
}
}
}
} else {
np.set("contactName", phoneNumber);
}
if (phoneNumber != null) {
np.set("phoneNumber", phoneNumber);
}
switch(state) {
case TelephonyManager.CALL_STATE_RINGING:
unmuteRinger();
np.set("event", "ringing");
device.sendPacket(np);
break;
case // Ongoing call
TelephonyManager.CALL_STATE_OFFHOOK:
np.set("event", "talking");
device.sendPacket(np);
break;
case TelephonyManager.CALL_STATE_IDLE:
if (lastPacket != null) {
// Resend a cancel of the last event (can either be "ringing" or "talking")
lastPacket.set("isCancel", "true");
device.sendPacket(lastPacket);
if (isMuted) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
unmuteRinger();
}
}, 500);
}
// Emit a missed call notification if needed
if ("ringing".equals(lastPacket.getString("event", null))) {
np.set("event", "missedCall");
np.set("phoneNumber", lastPacket.getString("phoneNumber", null));
np.set("contactName", lastPacket.getString("contactName", null));
device.sendPacket(np);
}
}
break;
}
lastPacket = np;
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SftpPlugin method onPacketReceived.
@Override
public boolean onPacketReceived(NetworkPacket np) {
if (np.getBoolean("startBrowsing")) {
ArrayList<String> paths = new ArrayList<>();
ArrayList<String> pathNames = new ArrayList<>();
List<StorageInfo> storageInfoList = SftpSettingsFragment.getStorageInfoList(context, this);
Collections.sort(storageInfoList, Comparator.comparing(StorageInfo::getUri));
if (storageInfoList.size() > 0) {
getPathsAndNamesForStorageInfoList(paths, pathNames, storageInfoList);
} else {
NetworkPacket np2 = new NetworkPacket(PACKET_TYPE_SFTP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
np2.set("errorMessage", context.getString(R.string.sftp_no_storage_locations_configured));
} else {
np2.set("errorMessage", context.getString(R.string.sftp_no_sdcard_detected));
}
device.sendPacket(np2);
return true;
}
removeChildren(storageInfoList);
if (server.start(storageInfoList)) {
if (preferences != null) {
preferences.registerOnSharedPreferenceChangeListener(this);
}
NetworkPacket np2 = new NetworkPacket(PACKET_TYPE_SFTP);
// TODO: ip is not used on desktop any more remove both here and from desktop code when nobody ships 1.2.0
np2.set("ip", server.getLocalIpAddress());
np2.set("port", server.getPort());
np2.set("user", SimpleSftpServer.USER);
np2.set("password", server.getPassword());
// Kept for compatibility, in case "multiPaths" is not possible or the other end does not support it
np2.set("path", "/");
if (paths.size() > 0) {
np2.set("multiPaths", paths);
np2.set("pathNames", pathNames);
}
device.sendPacket(np2);
return true;
}
}
return false;
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SystemVolumePlugin method sendEnable.
void sendEnable(String name) {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_SYSTEMVOLUME_REQUEST);
np.set("enabled", true);
np.set("name", name);
device.sendPacket(np);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class LanLink method receivedNetworkPacket.
private void receivedNetworkPacket(NetworkPacket np) {
if (np.hasPayloadTransferInfo()) {
Socket payloadSocket = new Socket();
try {
int tcpPort = np.getPayloadTransferInfo().getInt("port");
InetSocketAddress deviceAddress = (InetSocketAddress) socket.getRemoteSocketAddress();
payloadSocket.connect(new InetSocketAddress(deviceAddress.getAddress(), tcpPort));
payloadSocket = SslHelper.convertToSslSocket(context, payloadSocket, getDeviceId(), true, true);
np.setPayload(new NetworkPacket.Payload(payloadSocket, np.getPayloadSize()));
} catch (Exception e) {
try {
payloadSocket.close();
} catch (Exception ignored) {
}
Log.e("KDE/LanLink", "Exception connecting to payload remote socket", e);
}
}
packageReceived(np);
}
Aggregations