Search in sources :

Example 31 with NetworkPackage

use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.

the class NotificationsPlugin method sendNotification.

public void sendNotification(StatusBarNotification statusBarNotification, boolean requestAnswer) {
    Notification notification = statusBarNotification.getNotification();
    AppDatabase appDatabase = new AppDatabase(context);
    if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0 || (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 || (notification.flags & Notification.FLAG_LOCAL_ONLY) != 0) {
        //This is not a notification we want!
        return;
    }
    appDatabase.open();
    if (!appDatabase.isEnabled(statusBarNotification.getPackageName())) {
        return;
    // we dont want notification from this app
    }
    appDatabase.close();
    String key = getNotificationKeyCompat(statusBarNotification);
    String packageName = statusBarNotification.getPackageName();
    String appName = AppsHelper.appNameLookup(context, packageName);
    if ("com.facebook.orca".equals(packageName) && (statusBarNotification.getId() == 10012) && "Messenger".equals(appName) && notification.tickerText == null) {
        //HACK: Hide weird Facebook empty "Messenger" notification that is actually not shown in the phone
        return;
    }
    if ("com.android.systemui".equals(packageName) && "low_battery".equals(statusBarNotification.getTag())) {
        //HACK: Android low battery notification are posted again every few seconds. Ignore them, as we already have a battery indicator.
        return;
    }
    NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION);
    if (packageName.equals("org.kde.kdeconnect_tp")) {
        //Make our own notifications silent :)
        np.set("silent", true);
        //For compatibility with old desktop versions of KDE Connect that don't support "silent"
        np.set("requestAnswer", true);
    }
    if (sendIcons) {
        try {
            Bitmap appIcon = notification.largeIcon;
            if (appIcon != null) {
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                if (appIcon.getWidth() > 128) {
                    appIcon = Bitmap.createScaledBitmap(appIcon, 96, 96, true);
                }
                appIcon.compress(Bitmap.CompressFormat.PNG, 90, outStream);
                byte[] bitmapData = outStream.toByteArray();
                np.setPayload(bitmapData);
                np.set("payloadHash", getChecksum(bitmapData));
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("NotificationsPlugin", "Error retrieving icon");
        }
    }
    RepliableNotification rn = extractRepliableNotification(statusBarNotification);
    if (rn.pendingIntent != null) {
        np.set("requestReplyId", rn.id);
        pendingIntents.put(rn.id, rn);
    }
    np.set("id", key);
    np.set("appName", appName == null ? packageName : appName);
    np.set("isClearable", statusBarNotification.isClearable());
    np.set("ticker", getTickerText(notification));
    np.set("title", getNotificationTitle(notification));
    np.set("text", getNotificationText(notification));
    np.set("time", Long.toString(statusBarNotification.getPostTime()));
    if (requestAnswer) {
        np.set("requestAnswer", true);
        np.set("silent", true);
    }
    device.sendPackage(np);
}
Also used : Bitmap(android.graphics.Bitmap) NetworkPackage(org.kde.kdeconnect.NetworkPackage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 32 with NetworkPackage

use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.

the class RemoteKeyboardPlugin method notifyKeyboardState.

public void notifyKeyboardState(boolean state) {
    Log.d("RemoteKeyboardPlugin", "Keyboardstate changed to " + state);
    NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_KEYBOARDSTATE);
    np.set("state", state);
    device.sendPackage(np);
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Example 33 with NetworkPackage

use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.

the class ReceiveNotificationsPlugin method onCreate.

@Override
public boolean onCreate() {
    // request all existing notifications
    NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION_REQUEST);
    np.set("request", true);
    device.sendPackage(np);
    return true;
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Example 34 with NetworkPackage

use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.

the class RemoteKeyboardPlugin method onPackageReceived.

@Override
public boolean onPackageReceived(NetworkPackage np) {
    if (!np.getType().equals(PACKAGE_TYPE_MOUSEPAD_REQUEST) || (!np.has("key") && !np.has("specialKey"))) {
        // expect at least key OR specialKey
        Log.e("RemoteKeyboardPlugin", "Invalid package for remotekeyboard plugin!");
        return false;
    }
    if (RemoteKeyboardService.instance == null) {
        Log.i("RemoteKeyboardPlugin", "Remote keyboard is not the currently selected input method, dropping key");
        return false;
    }
    if (!RemoteKeyboardService.instance.visible && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.remotekeyboard_editing_only), true)) {
        Log.i("RemoteKeyboardPlugin", "Remote keyboard is currently not visible, dropping key");
        return false;
    }
    if (!handleEvent(np)) {
        Log.i("RemoteKeyboardPlugin", "Could not handle event!");
        return false;
    }
    if (np.getBoolean("sendAck")) {
        NetworkPackage reply = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_ECHO);
        reply.set("key", np.getString("key"));
        if (np.has("specialKey"))
            reply.set("specialKey", np.getInt("specialKey"));
        if (np.has("shift"))
            reply.set("shift", np.getBoolean("shift"));
        if (np.has("ctrl"))
            reply.set("ctrl", np.getBoolean("ctrl"));
        if (np.has("alt"))
            reply.set("alt", np.getBoolean("alt"));
        reply.set("isAck", true);
        device.sendPackage(reply);
    }
    return true;
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Example 35 with NetworkPackage

use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.

the class MprisPlugin method Seek.

public void Seek(int offset) {
    NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
    np.set("player", player);
    np.set("Seek", offset);
    device.sendPackage(np);
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Aggregations

NetworkPackage (org.kde.kdeconnect.NetworkPackage)41 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 SocketException (java.net.SocketException)3 Uri (android.net.Uri)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 DatagramSocket (java.net.DatagramSocket)2 InetAddress (java.net.InetAddress)2 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 Cipher (javax.crypto.Cipher)2 SSLSocket (javax.net.ssl.SSLSocket)2 JSONArray (org.json.JSONArray)2 Notification (android.app.Notification)1 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1