[NDK App and Java App] Working on a new VNC Server V1.86

337 posts
Thanks Meter: 81
By knoxbrder, Senior Member on 2nd February 2012, 07:02 AM
Post Reply Email Thread
** You need to have root to run this app! **

I have been hacking up a vnc server from old code I found on Google. I will try to get the changes merged into the original project; if that fails I will start a new project or just post the source.
This one works with my rooted Transformer Prime, a rooted Galaxy S2 and a CyanogenMod Nexus One perfectly. On a non-rooted Galaxy S2 everything works except the mouse/touch.

This uses the new Screenshot code for Android and either the "uinput" user space input device, the "input" command line tool to send keys, or direct access to the Linux keyboard device. It uses either the "uinput" user space input device if specified for the keyboard or the Linux touch device / mousepad device (like on my Prime).

I have been pushing the NDK app to /data/local/vncs using adb.
Open an "adb shell" or local connectbot session. cd /data/local. and then a command like below:

Try this first:

galaxy s2 has no mouse pointer: (touch won't work without root)
./vncs -t /dev/input/event2 -s -g -x 480 -y 800

galaxy nexus has no mouse pointer: (touch won't work without root)
./vncs -t /dev/input/event1 -s -n -x ? -y ? (I don't know the values for the nexus touch size or if it auto detects)

prime with keyboard has visible mouse pointer: (rooted ICS)
./vncs -t /dev/input/event5

prime without keyboard has no mouse pointer: (rooted ICS)
./vncs -t /dev/input/event3

nexus one with cyanogenmod: (rooted Gingerbread)
./vncs -t /dev/input/event3

local Escape key is "back" on remote Android device
local Windows or Home key is "home" on remote Android device
local F1 or Menu or Pg-Up key is "menu" on remote Android device
local F6 key is "camera" on some devices (not all)
local Pg-Dn key is "call" on some devices (not all)
local End key is "end call" and/or power on/off
local Alt-o / Alt-i is "power off/on" on some devices
local Alt-u is "volume up" on some devices
local Alt-d is "volume down" on some devices

Press F2 or Alt-p to pause/resume screen refresh. This is great for watching videos on the TV. If you don't disable the remote refresh then the video will jerk because of the screenshots being taken.
If you have a Prime with the keyboard then you can use the mouse pointer version and see what you are clicking on even with screen refresh off.

Press F4 or Alt-r to rotate the screen 90 degrees. 0,90,180,270 then back to 0. The connection disconnects for now so you will need to reconnect again. To keep reconnecting, in a shell on my laptop I use "while :; do vncviewer; sleep 1; done".

Press F3 or Alt-s to change the scaling, normal, half, quarter then back to normal. The connection disconnects for now so you will need to reconnect again. To keep reconnecting, in a shell on my laptop I use "while :; do vncviewer; sleep 1; done".

Press Alt-q to close the connection from the server side. It can be opened again from the client.

I haven't tested on many other devices yet. Let me know of failures or successes!

Command line switches on the server:
-h show help
-s swap red/blue colors
-g galaxy s2 touchscreen
-n galaxy nexus touchscreen
-x touchscreen maximim x
-y touchscreen maximim y
-r rotate mode 0,1,2,3 = 0,90,180,270 degrees, default is 0
-T touchscreen pointer rotate offset, 0-3=0,90,180,270, default is 0 (same rotation as screen)
-m magnification 1/m, 1=fullsize, 2=half size, 4=quarter size
-t touch device
-k keyboard device, default is uinput command
-p : password, default is none
-d : delay between events, default is 300000
-P : port, default is 5901
-32 32bpp; default is 32 for snapshot, 16 for framebuffer
-16 16bpp; default is 32 for snapshot, 16 for framebuffer
-o hack to send touch events on non-rooted device
-c red offset, red length, green offset, green length, blue offset, blue length; defaults 16,8,8,8,8,0
-R connect to remote host:remote port
-a average when scaling (slower but better looking)
-C reconnect to listener if connection dropped

Version 1.86

Version 1.86 includes many new features such as connect to remote vnc listener, deliver VNC Java client on port 5800+, average pixels when scaling, touchscreen pointer rotation offset and generic color sequence settings (needed for some devices).
If all connected clients support it then size and rotation are updated without disconnecting the client; if any client doesn't support it, then all clients are disconnected as it worked previously. Normally not a problem since most people only connect to a device with one client at a time.

Connect to your device from a java enabled web browser with something like if your normal port is 5901. The downloaded jar supports most things the standalone vnc clients support.

Version 1.86 includes a Java Control App as well.
It has the NDK app included in it so you only need to download the standalone exe if you don't want the Java App. The Java App extracts the NDK App when it runs and keeps it in its own Android directory structure (not in /data/local anymore).

The GUI is now compiled for Android 2.2+ and now includes two desktop widgets: 1x1 and 4x1 and an option to turn on a notification that shows the current server status and a start/stop button. Notification icon and widgets change icon to give visual indication when the server is running.

Custom Launchers and other apps can call activities to start/stop the server.
Tasker Action Intent setup:
Action: (or STOP)
Cat: Launcher
Target: Broadcast Receiver

For instance, I have my phone setup to start the server when I place it in the dock or connect power.

I found/fixed a small bug with the refresh code, hopefully that will a) keep the widgets/notifications updating unless you stopped them from the menu and b) fix the "VNCPrefs has Stopped" display.

** You need to have root to run this app! **

You can configure everything from the Java GUI. Check out the About/Help menu option to see the list of special keys and their functions.
Also look in the Help section for a quick guide on how to configure the options for different types of devices. Post if you find some more working or not working devices.

+ done: scale viewer
+ done: switch between portrait/landscape in viewer
+ done: launch/control from gui
+ create generic option for specifying pointer setup so anyone can add a new device (superseded by using uinput)
+ fix input on undocked Prime (fixed with uinput)
+ add a way to start/stop the server from an email, sms or google voice
+ http server/applet
- upgrade to latest vnc server library/applet
- ctrl key (for connectbot mainly)

Prime specifc keys:
- page up/down keys
- home/end keys
- insert/delete keys
- media/volume keys
- other prime hard keys: wireless/mouse/bluetooth/contrast/camera/etc
Attached Files
File Type: apk vnclauncher.apk - [Click for QR Code] (274.2 KB, 3491 views)
File Type: zip - [Click for QR Code] (189.9 KB, 2854 views)
The Following 23 Users Say Thank You to knoxbrder For This Useful Post: [ View ] Gift knoxbrder Ad-Free
2nd February 2012, 02:01 PM |#2  
Junior Member
Flag Rotterdam
Thanks Meter: 1
I'm trying this on my rooted Galaxy Nexus (4.0.2) using connectbot, but I keep on getting "cannot execute - Permission denied" even though I'm using superuser prompt.

EDIT: I forgot to set permissions to the file, it works now, although the framerate seems a bit low and the colors are inverted...
2nd February 2012, 04:13 PM |#3  
OP Senior Member
Thanks Meter: 81
I only get a couple frames per second. I don't think the snapshot code is very fast.

Try the command line switch -s to swap the red/blue colors.
-h shows all the options.
The Following User Says Thank You to knoxbrder For This Useful Post: [ View ] Gift knoxbrder Ad-Free
3rd February 2012, 01:17 PM |#4  
Junior Member
Flag Rotterdam
Thanks Meter: 1
The -s switch does the trick with the inverted colors. Unfortunately I can not get keyboard and mouse input to work.
About the low framerate, I can see that "surfaceflinger" is taking up a lot of cpu usage when I start vncs, maybe that has something to do with it...

Please keep up the good work, I really like it already!
The Following User Says Thank You to glenn85 For This Useful Post: [ View ] Gift glenn85 Ad-Free
3rd February 2012, 06:23 PM |#5  
OP Senior Member
Thanks Meter: 81
Did you try the -g option for the pointer? That format is what the Galaxy S2 uses. The Nexus may be the same.

If that doesn't help, read on.....

Since your device is rooted, do you have busybox installed?

If so, can you post the output of "which input"? I currently use that program to inject the keys and I have found it to work on several devices although it is a bit slow.

For the pointer, try using the -t option to specify different /dev/input/eventX options where X is usually 0 - 6. An "ls -l /dev/input/" will show you which ones are available. Different phones/tablets use different event devices and I haven't tried to figure out how to auto detect which is which.

If you run something like "od -x /dev/input/eventX", where X is 0 - 7, and touch the touchscreen you should get output on the one the touchscreen uses.

If you find the right -t option by using od, but still can't get the mouse to work over VNC, post the output of this:
- run "od -x /dev/input/event3" (or whichever event file works for you)
- carefully touch/release the screen as quickly as possible so you get one or two "touch" events outputting from the od command
- post the values (I would do this over adb so you can copy/past the output)

I will look at the output to see how it differs from the devices I have tested.
5th February 2012, 01:35 AM |#6  
Flag Massachusetts
Thanks Meter: 10
Also running a Galaxy Nexus with 4.0.2 (VZW, deodexed but otherwise stock ROM, rooted [as all Nexus devices should be]). The -s fixed the color inversion, with or without -g I can't use the touch or keyboard input (although I wasn't thorough about keyboard testing).

I would like to request a scaling factor or allowing 90 degree rotation since the 1280 pixel vertical resolution exceeds my 1080p monitor, but that's pretty minor as of now.

# which input
It looks like the touchscreen is actually on event1:
[email protected]:/ # od -x /dev/input/event1                                       
0000000     00d2    0000    0f70    0001    0003    0039    001e    0000
0000020     00d2    0000    0f70    0001    0003    0030    000e    0000
0000040     00d2    0000    0f8f    0001    0003    003a    0081    0000
0000060     00d2    0000    0f8f    0001    0003    0035    01ca    0000
0000100     00d2    0000    0f8f    0001    0003    0036    0120    0000
0000120     00d2    0000    0fad    0001    0000    0000    0000    0000
0000140     00d2    0000    2d5c    0001    0003    0039    ffff    ffff
0000160     00d2    0000    2d5c    0001    0000    0000    0000    0000
Here are the input devices:
# ls /dev/input
Thanks for your work on this, I really miss having a VNC server on my phone!
6th February 2012, 04:37 AM |#7  
OP Senior Member
Thanks Meter: 81
New Version 1.1 up; see first post.
Added scaling and rotation.
Tweaked the input handling.

For Galaxy S2 try ./vncs -t /dev/input/event2 -s -g -x 480 -y 800.
Other devices let me know if this version works better.
6th February 2012, 09:16 AM |#8  
Junior Member
Flag Rotterdam
Thanks Meter: 1
The touchscreen indeed seems to be on event1. So I tried the following commands:
./vncs -t /dev/input/event1 -s -g -x 720 -y 1280
./vncs -t /dev/input/event1 -s

But mouse input still doesn't work, unfortunately.
I also found out when the phone goes to stand-by mode while running vncs, the touchscreen stops working at all. Had to take out my battery to restart the phone...
6th February 2012, 02:41 PM |#9  
OP Senior Member
Thanks Meter: 81
I forgot to actually attach the new version.
Check -h when you run it to make sure it says version 1.1.

See if this fixes the event problem.

I have never seen the device hang when it goes to sleep.
I will see if I can reproduce that.
6th February 2012, 10:12 PM |#10  
Flag Massachusetts
Thanks Meter: 10
Still no luck on the VZW Galaxy Nexus (but the scaling is much appreciated!). Please let me know if you'd like any additional debugging information from me.
6th February 2012, 10:29 PM |#11  
OP Senior Member
Thanks Meter: 81
Please try to capture a couple more touchscreen presses. I don't think there is enough information in your previous log.
I see the headers, and x/y movement. But I'm not sure I see the actual "finger down/release". Or I don't understand it.

Post Reply Subscribe to Thread

galaxy s2, nexus one, prime, vnc server

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes