Android X Server
Posted by sky | Tags: Android, Debian, Linux, Open-Source, Personal, ssh, testing, window manager
The XServer XSDL is a complete X Window System server for Android which uses SDL ported by Sergii Pylypenko (pelya). The source code is hosted at git https://github.com/pelya/xserver-xsdl.
He has also ported several games to the Android OS.
With this X server installed, there is no longer a need to use the combination of a Linux X server (eg. tightvncserver) and an Android VNC client app which is much much slower.
When you first launched the X server app, you can change device config to configure how the left/right mouse click behavior is simulated, to remap keyboard keys, and other options. (Though there is no explanation of what they do)
The escape and insert keys are needed, so most would want to remap some keys to them. It seems the X server does not recognize the "Caps Lock" key, so I have to remap another key to it.
I use the X server mainly to access Debian Linux installed on my Android system. For ref: see Running Debian Armhf alongside Android There are also other easier ways to install a variety of Linux on an Android system which can be googled.
For Debian kit, I run the Linux ssh server with deb s (in a command line).
Note: the debian.img is mounted at boot time, see Debian Android with no Root
Below, I run the script to login to Linux via the ssh, and if its successful, the script will launch the Android X server via the am command.
1 #!/system/bin/sh
2 # prompt for ssh login to localhost
3 while true; do
4 echo -n "Login user: "
5 read user
6 case $user in
7 "") break;;
8 exit ) break;;
9 term ) break;;
10 * )
11 grps=$(/usr/bin/groups $user 2> /dev/null)
12 if [ -z "$grps" ]; then
13 echo "sorry"
14 continue
15 fi
16 # ssh
17 if /usr/bin/ssh "${user}@localhost" 'nohup waitx > /dev/null 2>&1 &'; then
18 #pid=$(/usr/bin/pgrep -n -uterm ssh)
19 # start X
20 /system/bin/am start --user 0 -n x.org.server/.MainActivity
21 fi
22 exit
23 esac
24 done
25 exit 1
26
The script will prompt for the login name, it will simply exit if you either enter exit, or term, or you hit <Enter> without entering anything. It will say sorry if it thinks the entered login name is not valid, and it will prompt for the login again. Otherwise, it runs the ssh command to login to the local ssh server.
The script itself is normal, it does not require root access. Typically, the sshd_config should have "PermitRootLogin no" so that root account cannot login via ssh. You can allow specific users with AllowUsers option.
In order to do Linux administration, you will need an account in the sudo group. So, while using root access, run this command to add a user to the sudo group: adduser <username> sudo
This also depends on whether the sudo group can execute any command. In the /etc/sudoers file, if you find the below, then any members in the sudo group can use the sudo command.
1 # Allow members of group sudo to execute any command
2 %sudo ALL=(ALL:ALL) ALL
3
For convenience, I set the initial command preference of the Android Terminal Emulator by Jack Palevich to run my login script. So, once I launch the terminal app, the login prompt is displayed. If I login successfully, then the X server is launched.
Also, while using root access, add the below line to /etc/passwd
1 term:x:10125:10125::/data/data/jackpal.androidterm/app_HOME:/bin/sh
2
The userid of my Android Terminal Emulator is 10125. This is auto-assigned by Android, so it will be different. The line is added so that the ssh command can be run from the Android Terminal Emulator.
The ssh runs another script waitx after login.
1 #!/bin/sh
2 # if X is not killed, no wait is needed
3 if [ -z "$(netstat -lp | grep -i x11)" ]; then
4 sleep 7
5
6 wait=4
7 while [ -z "$(netstat -lp | grep -i x11)" ]; do
8 if [ $wait -eq 0 ]; then
9 echo "not waiting .. quit"
10 exit
11 fi
12 sleep 1
13 $((wait--))
14 done
15 fi
16 startwm
17
The waitx script checks whether the X server is running, and if it is running, then it runs another script startwm which will then run i3 the X window manager that I am using.
As the X server is only launched after the first successful login, one will have to wait a longer time initially before using any X applications. (try login script again if the X window manager is not displayed)
My startwm script looks like:
1 #!/bin/sh
2
3 echo "Staring wm"
4
5 xrdb -merge ~/.Xresources
6 xmodmap ~/.xmodmaprc
7
8 #wmii -r python/wmiirc &
9 /usr/bin/i3 &
10