Virtual android phones

Try to create virtual android phones on server.

Ref.: Virtual Smartphone over IP

Some android emulators:

  1. Android-x86
    http://www.android-x86.org/
  2. ARChon Custom Runtime
    http://archon-runtime.github.io/
  3. Official Android SDK Emulator w/HAXM
    http://developer.android.com/sdk/index.html
  4. Android on Intel Architecture
    https://01.org/android-ia
  5. ARC Welder
    https://developer.chrome.com/apps/getstarted_arc

Remote control

Linux Ubuntu 14.04 64bit

Prerequisite:

  1. Android-x86
  2. VirtualBox
  3. Python…

Steps

  1. download android-x86-5.1-rc1.iso
  2. dkpg -i virtualbox-5.0_5.0.12-104815-Ubuntu-trusty_amd64.deb
    Need to enable Intel VT-X or AMD-V in your bios configuration
  3. install android-x86 in virtualbox
  4. cotrol virtualbox on console
    Start VM
    If run as root:
  • sudo -u jeff -H VBoxManage startvm Android
    background mode
  • sudo -u jeff -H VBoxHeadless -s Android -v on -e “TCP/Ports=31000”
    Stop VM
  • sudo -u jeff -H VBoxManage startvm Android

*

finish install

Test

TCP socket

In android-x86 press Alt+F1 entry console mode
netcfg
check ip
ifconfig eth0 xx.xx.xx.xx netmask 255.255.255.0
Alt+F7 GUI mode

1, Server send a message -> Android VM app receive the message

Server
client.py

# -*- coding: utf-8 -*-
import socket 
def Main():
    host = '192.168.42.142'
    port = 10090         
    mySocket = socket.socket()
    mySocket.connect((host,port))        
    message = input(" -> ")         
    while message != 'e':
        mySocket.send(message.encode())            
        message = input(" -> ")                 
    mySocket.close() 
if __name__ == '__main__':
    Main()

Android VM app

SockerService.java

package com.example.user.myapplication;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketService extends IntentService {
    public static final String ACTION_MyIntentService = "com.example.user.myapplication.RESPONSE";
    public static final String ACTION_MyUpdate = "com.example.user.myapplication.UPDATE";
    public static final String EXTRA_KEY_IN = "EXTRA_IN";
    public static final String EXTRA_KEY_OUT = "EXTRA_OUT";
    public static final String EXTRA_KEY_UPDATE = "EXTRA_UPDATE";
    private Context context;
    private String name; 
    private int Port = 10090;
    private ServerSocket server_socket;
    private Socket socket;
    private InputStream in;
    private OutputStream out;
    private BufferedReader reader; 
    private String messgae = null;
    public SocketService() {
        super("SocketService");
        // TODO Auto-generated constructor stub
    }
    public SocketService(Context context, String name) {       
        super("SocketService");
        this.context = context;
        this.name = name;
    }
    @Override
    protected void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
        while (true) {
            try {              
                socket = server_socket.accept(); 
                in = socket.getInputStream();
                reader = new BufferedReader(new InputStreamReader(in));
                messgae = reader.readLine();  
                Intent intentResponse = new Intent();
                intentResponse.setAction(ACTION_MyIntentService);
                intentResponse.addCategory(Intent.CATEGORY_DEFAULT);
                intentResponse.putExtra(EXTRA_KEY_OUT, messgae.toString());
                sendBroadcast(intentResponse);
            } catch (Exception e) {
                e.printStackTrace();
                Log.i("service exception", e.getMessage());
            }
        }
    } 
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        try {
            server_socket = new ServerSocket(Port); 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace(); 
        }
    }
    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.user.myapplication" >
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".SocketService" >
        </service>
    </application>
</manifest>

*

run

2, Android VM send a message once finishing satrt -> Server receive the message

~ TODO ~

Use simple-web-vnc

First, get the application window name.

$ xwininfo -root -tree | grep VirtualBox
0x4000001 “VirtualBox”: (“VirtualBox” “VirtualBox”) 10x10+10+10 +10+10
0x1a0000c “Oracle VM VirtualBox Manager”: (“VirtualBox” “VirtualBox”) 975x513+0+0 +765+196
0x420000c “Android [Running] - Oracle VM VirtualBox”: (“VirtualBox” “VirtualBox”) 800x622+0+0 +238+176

Modify code in Simple-web-vnc
server.go

func (conn *connection) appStreaming() { 
    windowName :=  "Android [Running] - Oracle VM VirtualBox" 
    wn := C.CString(windowName)
    conn.appHandle = C.app_create(1024, 0,0, 800, 600, wn);
    ...
}

Notice: Mouse position mapping still has some problems between Android VM and canvas !!!

Demo