KDE Connect – Link your Android device to your KDE desktop

KDE Connect app icon on my Samsung Galaxy Note II

KDE Connect app icon on my Samsung Galaxy Note II

KDE Connect is a nice tool that links your Android phone or tablet seamlessly via WiFi to KDE on your PC (the latter can be connected via WiFi or cable to the network). It allows your KDE desktop to receive notifications, files and media player commands from your Android device. The available KDE Connect plug-ins are:

Battery report
Periodically report battery status

Clipboard sync
Share the clipboard content

Multimedia remote controls
Control audio/video from your phone
(pause; first track; previous track; next track; last track; change volume)

Notification sync
Access your notification from other devices

Ping
Send and receive pings

Telephony notifier
Send notifications from SMS and calls

You will need to install the Android KDE Connect application on your Android device, and the Linux KDE Connect application on your PC.

Install the KDE Connect app on your Android device from the Google Play Store. You will then see the KDE Connect icon on the apps screen of your Android device.

For Gentoo users an ebuild for KDE Connect is available in the Gentoo KDE team’s testing overlay, so here are the instructions on how to install KDE Connect on your PC from there.

Firstly, mask the KDE overlay so that none of the packages in it interferes with the KDE software you installed from the main Portage tree:

# echo "*/*::kde" >> /etc/portage/package.mask

Then unmask the KDE Connect package in the KDE overlay:

# echo "kde-misc/kdeconnect" >> /etc/portage/package.unmask

N.B. If /etc/portage/package.mask is a directory rather than a file (either is possible) in your installation, and if /etc/portage/package.unmask is a directory rather than a file (either is possible) in your installation, use the following commands instead of the above two commands:

# echo "*/*::kde" > /etc/portage/package.mask/kde_overlay
# echo "kde-misc/kdeconnect" > /etc/portage/package.unmask/kdeconnect

Now add the KDE overlay and merge the package:

# layman -a kde
# emerge kdeconnect

If a firewall is running on your PC, you will need to configure it to allow tcp and udp traffic via a specific range of ports (1714 to 1764). I have UFW running on my main laptop, so in my case I used the following commands:

# ufw allow proto tcp to any port 1714:1764
# ufw allow proto udp to any port 1714:1764

The rules should look like this:

# ufw status verbose | grep 1714
1714:1764/tcp ALLOW IN Anywhere
1714:1764/udp ALLOW IN Anywhere
1714:1764/tcp ALLOW IN Anywhere (v6)
1714:1764/udp ALLOW IN Anywhere (v6)

If you have the KConfig Module kcm_ufw installed on your PC then you can instead use System Settings > Firewall to add the UFW rules via the KDE GUI.

By the way, to check which KConfig modules are installed on your PC you can use the following command under your user account:

$ kcmshell4 --list

Using KDE Connect is not difficult, so I will leave you to play with it. Obviously make sure WiFi is enabled on your Android device, and that it and your PC are connected to the same network. Tap on the KDE Connect icon on your Android device to launch the app, and you should see your PC’s name listed under CONNECTED DEVICES. Tap on the PC name and you should see the following screen:

KDE Connect screen

KDE Connect screen

If you tap on ‘Send ping’, the KDE Notification widget on the KDE System Tray should pop up a notification.

You can see what KDE Connect plug-ins are available, and select/deselect them:

KDE Connect plugins

KDE Connect plugins

KDE Connect also enables you to use your Android device as a remote control for media players running on your PC. When you launch a media player in KDE its name will appear in a list of selectable players in KDE Connect, and the name of the track currently playing will also be displayed:

KDE Connect - Remote control

KDE Connect - Remote control

When you select a file on your Android device and tap the Share icon, KDE Connect will be one of the options displayed on the ‘Share via’ menu. This is a handy way to send files from your Android device to your PC. The KDE Notification widget on your PC will notify you when the file has been transferred to ~/Desktop/ on your PC:

KDE on your PC notifies you when a file has been sent via KDE Connect

KDE on your PC notifies you a file has been sent via KDE Connect

You should also get notifications on your KDE desktop when someone phones or sends you an SMS.

Kudos and many thanks to the people responsible for KDE Connect. KDE is already a superb desktop environment, and with the addition of KDE Connect it is better still.

‘Server not found’ by browser at launch

I haven’t had any significant Linux problems or new requirements in the last few months, hence no new posts here. My last real problem was back in June 2013 when I rolled my Gentoo installation to latest using Portage and found that, whenever I launched Firefox, it displayed the ‘Server not found’ page and I had to click ‘Try Again’, and then Firefox displayed the expected Web site. From then onwards, Firefox would work as expected until I exited the application. Thunderbird was also unable to access e-mail servers on the first attempt after it was launched. The same thing happened in Sabayon Linux when I rolled to latest using Entropy a couple of days later. Anyway, here is how I fixed the problem in both distributions.

First I used Wireshark to see what was going on, and it transpired that Gentoo (and Sabayon) was sending an IPv4 request followed quickly by an IPv6 request, but the reply to the IPv6 request was being received first and was a ‘server not found’ message since my ISP does not support IPv6 and my router apparently does not handle IPv6 requests correctly. Gentoo (and Sabayon) then used an IPv4 address when I clicked ‘Try Again’ in the browser window, and thereafter Firefox always dispayed the expected Web sites.

I should point out that IPv6 is enabled in the kernels I use and I’ve never before had to disable IPv6 in Firefox (or system-wide) on the affected laptops. So why the change in functionality, I wonder?

With Wireshark capturing packets, when I launched Firefox I was seeing a server failure message indicating “AAAA” (IPv6) instead of “A” (IPv4). To stop this happening I could have chosen any one of the three following solutions:

1. I could have used about:config in Firefox (and Config Editor in Thunderbird) to change the value of network.dns.disableIPv6 to true instead of false.

2. I could have disabled IPv6 system-wide by editing /etc/modprobe.d/aliases.conf and uncommenting the line “alias net-pf-10 off“.

3. I could have forced the getaddrinfo() function in glibc to make the IPv4 and IPv6 requests sequentially rather than in parallel.

Just for the fun of it I chose the third option on a couple of my laptops, and, as they use NetworkManager, this is how I did it:

fitzcarraldo@aspire5536 ~ $ su
Password:
aspire5536 fitzcarraldo # cat /etc/resolv.conf
# Generated by resolvconf
domain home
nameserver 192.168.1.254
aspire5536 fitzcarraldo # cd /etc/NetworkManager/dispatcher.d/
aspire5536 dispatcher.d # touch 06-dhclientoptions
aspire5536 dispatcher.d # nano 06-dhclientoptions
aspire5536 dispatcher.d # cat 06-dhclientoptions
#!/bin/bash
echo "options single-request" >> /etc/resolv.conf
aspire5536 dispatcher.d # chmod +x /etc/NetworkManager/dispatcher.d/06-dhclientoptions
aspire5536 dispatcher.d # # Now I disconnect then reconnect to the network
aspire5536 dispatcher.d # cat /etc/resolv.conf
# Generated by resolvconf
domain home
nameserver 192.168.1.254
options single-request
aspire5536 dispatcher.d #

As you can see above, I added a two-line Bash script 06-dhclientoptions in the directory /etc/NetworkManager/dispatcher.d/ that appends the line “options single-request” (without the quotes) to the contents of the file /etc/resolv.conf. The addition of the line “options single-request” in resolve.conf causes the getaddrinfo() function in glibc to make the IPv4 and IPv6 requests sequentially rather than in parallel. With this change, Firefox and Thunderbird no longer have a problem accessing the Internet the first time they are launched.

From “man 5 resolv.conf” under “options”:

single-request (since glibc 2.10)
sets RES_SNGLKUP in _res.options. By default, glibc performs IPv4 and IPv6 lookups in parallel since version 2.9. Some appliance DNS servers cannot handle these queries properly and make the requests time out. This option disables the behavior and makes glibc perform the IPv6 and IPv4 requests sequentially (at the cost of some slowdown of the resolving process).

single-request-reopen (since glibc 2.9)
The resolver uses the same socket for the A and AAAA requests. Some hardware mistakenly sends back only one reply. When that happens the client system will sit and wait for the second reply. Turning this option on changes this behavior so that if two requests from the same port are not handled correctly it will close the socket and open a new one before sending the second request.

I had to use NetworkManagerDispatcher to add the line “options single-request” to /etc/resolv.conf because NetworkManager overwrites /etc/resolv.conf if you edit it manually.

UPDATE (February 4, 2014): As I have recently seen the line “options single-request” occurring more than once in the file /etc/resolv.conf I now recommend /etc/NetworkManager/dispatcher.d/06-dhclientoptions consists of the following:

#!/bin/bash
if grep -q "options single-request" /etc/resolv.conf; then
    exit
else
    echo "options single-request" >> /etc/resolv.conf
fi

Not all laptops are designed equal

Over time it is common for fans in laptops to become clogged with dust, fluff and even hair. The symptoms are usually a hotter laptop and a noisier fan that runs more frequently. The solution is to open up the laptop’s body in order to get at the fan and remove the crud with tweezers and by blowing. However, dismantling many laptops to access the fan makes the Mission Impossible break-in look simple, and this seems to be getting worse as laptop prices continue to decrease. If you are not confident you can unblock the fan yourself, you’ll have to find a local computer repair shop and you may find it’s not cheap. For some models the dismantling procedure can be so complicated that people post videos on YouTube. Often it is necessary to remove numerous screws, ribbon cables, jumper leads, plastic strips and the keyboard. In some cases you have to disassemble the laptop almost entirely. Fortunately, in the case of RAM modules there is often a hatch in the laptop’s base to facilitate access, but even adding or replacing RAM modules can sometimes be a major task (I used to own an Acer laptop that required the laptop base and keyboard to be removed in order to access the RAM modules).

Not long ago I had the misfortune to have to dismantle an Acer Aspire 5536-643G25Mn and a Toshiba Satellite C660-1J2 to remove accumulated fluff from the fans. I had to study YouTube videos carefully and could not believe how difficult it was to get access to the fan in the Acer Aspire. Dismantling the Toshiba Satellite to access the fan was not quite as bad as the Acer Aspire but was still a major task and, despite being as careful as possible, I still managed to break a fragile plastic lug on one of the base panels.

Last week my main laptop, a Compal NBLB2, seemed to be running a little hotter than usual, so I decided it was time to check if its fan also needed cleaning. What a pleasure that was in comparison to the other manufacturers’ laptops. The NBLB2 has a large plate in the base that, by removing only three screws (see the first photograph below), allows easy access to the fan and RAM modules. In less than five minutes I was able to remove a wad of fluff from the fan, replace the plate and power up the laptop again. Hats off to Compal for thinking about maintenance when designing this laptop. I only wish other laptop manufacturers did the same.

So, next time you need to buy a new laptop, do some research on how easy it will be to access the fan in case it needs to be cleaned. Look at the laptop’s base and check on the Web for a service manual, a YouTube video of it being disassembled, and comments in laptop/notebook forums. At least then you’ll know whether you stand a chance of avoiding paying a repair shop just to remove crud that inevitably builds up over time in the fan.

Base of Compal NBLB2 showing screws removed from main base plate

Base of Compal NBLB2 showing the 3 screws removed from the main base plate.

Base of Compal NBLB2 with main plate removed

Base of Compal NBLB2 with main plate removed. Notice how easy it is to access the fan and RAM modules.

How to prevent a USB mouse auto-suspending in Linux when a laptop’s power supply is disconnected

I found that my USB mouse (and external USB keyboard) went to sleep when the mains power supply was disconnected from my laptop. This was annoying because I had to click a mouse button and wait a couple of seconds in order to wake up the mouse. You can see from the console output below that several USB devices were being auto-suspended when I unplugged the laptop PSU:

# # PSU is currently connected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 on 12 BCM2046 Bluetooth Device
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera
2-1.6 on 1.5 USB Keyboard
# # Now I will disconnect the PSU...
# # PSU is currently disconnected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 auto 1.5 USB Laser Mouse
1-1.3 auto 12 BCM2046 Bluetooth Device
2-1.2 auto 12 Fingerprint Sensor
2-1.3 auto 480 USB 2.0 Camera
2-1.6 auto 1.5 USB Keyboard
#

I found out the Vendor ID (046d) and Product ID (c052) of my Logitech NX50 USB portable/travel mouse by unplugging then reconnecting the USB mouse and using the dmesg command:

[13628.909728] usb 1-1.2: USB disconnect, device number 5
[13634.454132] usb 1-1.2: new low-speed USB device number 6 using ehci_hcd
[13634.535107] usb 1-1.2: New USB device found, idVendor=046d, idProduct=c052
[13634.535111] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[13634.535113] usb 1-1.2: Product: USB Laser Mouse
[13634.535115] usb 1-1.2: Manufacturer: Logitech
[13634.540168] input: Logitech USB Laser Mouse as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input17
[13634.540582] hid-generic 0003:046D:C052.0005: input,hidraw0: USB HID v1.10 Mouse [Logitech USB Laser Mouse] on usb-0000:00:1a.0-1.2/input0

First I tried creating a local Udev rule:

# cat /etc/udev/rules.d/91-local.rules
ACTION=="add", SUBSYSTEM=="usb", ATTR{product}=="USB Laser Mouse", ATTR{power/control}="on"

That didn’t stop the mouse from auto-suspending (and neither did “Logitech USB Laser Mouse” instead of “USB Laser Mouse”), so I tried creating a Udev rule specifying the Vendor ID and Product ID of the mouse:

# cat /etc/udev/rules.d/91-local.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTR{idProduct}=="c052", TEST=="power/control", ATTR{power/control}="on"

That didn’t stop the mouse from auto-suspending either.

Then I remembered that laptop-mode-tools is installed on my laptop:

# eix laptop-mode-tools
[I] app-laptop/laptop-mode-tools
Available versions: 1.60-r1 (~)1.62-r1 {(+)acpi apm bluetooth scsi}
Installed versions: 1.62-r1(18:10:15 11/01/13)(acpi bluetooth -apm -scsi)
Homepage: http://www.samwel.tk/laptop_mode/
Description: Linux kernel laptop_mode user-space utilities

So then I tried adding the mouse model to the blacklist in /etc/laptop-mode/conf.d/usb-autosuspend.conf by making AUTOSUSPEND_USBID_BLACKLIST="046d:c052" as shown below:

#
# Configuration file for Laptop Mode Tools module usb-autosuspend.
#
# For more information, consult the laptop-mode.conf(8) manual page.
#


###############################################################################
# USB autosuspend settings
# ------------------------
#
# If you enable this setting, laptop mode tools will automatically enable the
# USB autosuspend feature for all devices.
#
# NOTE: Some USB devices claim they support autosuspend, but implement it in a
# broken way. This can mean keyboards losing keypresses, or optical mice turning
# their LED completely off. If you have a device that misbehaves, add its USB ID
# to the blacklist below and complain to your hardware vendor.
################################################################################

# Enable debug mode for this module
# Set to 1 if you want to debug this module
DEBUG=0

# Enable USB autosuspend feature?
# Set to 0 to disable
CONTROL_USB_AUTOSUSPEND="auto"

# Set this to use opt-in/whitelist instead of opt-out/blacklist for deciding
# which USB devices should be autosuspended.
# AUTOSUSPEND_USE_WHITELIST=0 means AUTOSUSPEND_*_BLACKLIST will be used.
# AUTOSUSPEND_USE_WHITELIST=1 means AUTOSUSPEND_*_WHITELIST will be used.
AUTOSUSPEND_USE_WHITELIST=0

# The list of USB IDs that should not use autosuspend. Use lsusb to find out the
# IDs of your USB devices.
# Example: AUTOSUSPEND_USBID_BLACKLIST="046d:c025 0123:abcd"
AUTOSUSPEND_USBID_BLACKLIST="046d:c052"

# The list of USB driver types that should not use autosuspend.  The driver
# type is given by "DRIVER=..." in a USB device's uevent file.
# Example: AUTOSUSPEND_USBID_BLACKLIST="usbhid usb-storage"
AUTOSUSPEND_USBTYPE_BLACKLIST=""

# The list of USB IDs that should use autosuspend. Use lsusb to find out the
# IDs of your USB devices.
# Example: AUTOSUSPEND_USBID_WHITELIST="046d:c025 0123:abcd"
AUTOSUSPEND_USBID_WHITELIST=""

# The list of USB driver types that should use autosuspend.  The driver
# type is given by "DRIVER=..." in a USB device's uevent file.
# Example: AUTOSUSPEND_USBTYPE_WHITELIST="usbhid usb-storage"
AUTOSUSPEND_USBTYPE_WHITELIST=""

# Trigger auto-suspension of the USB deivce under conditional circumstances
BATT_SUSPEND_USB=1
LM_AC_SUSPEND_USB=0
NOLM_AC_SUSPEND_USB=0

# USB Auto-Suspend timeout in seconds
# Number of seconds after which the USB devices should suspend
AUTOSUSPEND_TIMEOUT=2

And now the mouse no longer suspends when I unplug the PSU:

# # PSU is currently connected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 on 12 BCM2046 Bluetooth Device
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera
2-1.6 on 1.5 USB Keyboard
# # Now I will disconnect the PSU...
# # PSU is currently disconnected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 auto 12 BCM2046 Bluetooth Device
2-1.2 auto 12 Fingerprint Sensor
2-1.3 auto 480 USB 2.0 Camera
2-1.6 auto 1.5 USB Keyboard
# # Now I will reconnect the PSU...
# # PSU is currently connected.
# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
1-1.3 on 12 BCM2046 Bluetooth Device
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera
2-1.6 on 1.5 USB Keyboard
#

So configuring laptop-mode-tools solved the problem with the mouse. Mind you, I will probably simply make CONTROL_USB_AUTOSUSPEND="no" in /etc/laptop-mode/conf.d/usb-autosuspend.conf, as I don’t want the internal USB devices in my laptop (Bluetooth adapter, fingerprint sensor and Webcam) to auto-suspend either.

Follow

Get every new post delivered to your Inbox.

Join 49 other followers