diff --git a/host/bins/cfc-0.1.0-x64.deb b/host/bins/cfc-0.1.0-x64.deb index f5b9776..63a5cc3 100644 Binary files a/host/bins/cfc-0.1.0-x64.deb and b/host/bins/cfc-0.1.0-x64.deb differ diff --git a/host/src/pack/dpkg/etc/rc.civ b/host/src/pack/dpkg/etc/rc.civ index 06ebdc3..8da5660 100755 --- a/host/src/pack/dpkg/etc/rc.civ +++ b/host/src/pack/dpkg/etc/rc.civ @@ -25,6 +25,19 @@ then sed -i "s%/home/kylin/civ/.userdata/username.img%${HOME}/.userdata/${USER}.img%g" $HOME/.intel/.civ/penguin-peak.ini sed -i "s%/home/kylin/Android/Pictures%${HOME}/Android/Pictures%g" $HOME/.intel/.civ/penguin-peak.ini sed -i "s%/home/kylin/Android/Download%${HOME}/Android/Download%g" $HOME/.intel/.civ/penguin-peak.ini + + SYS_MEM_SIZE=`cat /proc/meminfo | grep MemTotal | grep -v grep | awk '{print $2}'` + SYS_MEM_SIZE_G=$((SYS_MEM_SIZE/1024/1024)) + # It may smaller than the real memory size since some reserved + # memory not exposed to OS. + if [ "$SYS_MEM_SIZE_G" -le "8" ]; + then + echo "Macine with ~ 8G memory loaded, allocate 3G system memory to AVM." + sed -i "s%^size=4G$%size=3G%g" $HOME/.intel/.civ/penguin-peak.ini + else + # the size=4G is the default configuration in penguin-peak.ini, do nothing. + echo "Machine with large than 8G memory loaded, do nothing." + fi fi if [ ! -d $HOME/.userdata ] diff --git a/host/src/pack/dpkg/etc/rc.civ.post b/host/src/pack/dpkg/etc/rc.civ.post index 042e5f1..de1176a 100755 --- a/host/src/pack/dpkg/etc/rc.civ.post +++ b/host/src/pack/dpkg/etc/rc.civ.post @@ -1,32 +1,65 @@ -#!/bin/sh -e +#!/bin/bash -e -sleep 10 CIV_PATH=/opt/civ/data/Release_Deb -${CIV_PATH}/scripts/stream & +function is_civ_ready() { + for i in {0..9}; do + timeout 1 adb connect vsock:3:5555 && break + done + + for i in {0..9}; do + if [ "$(adb -s vsock:3:5555 shell getprop sys.boot_completed)" == "1" ] ; then + return 0 + break + fi + sleep 1 + done + + return -1 +} + +function launch_lg_input_client() +{ + # needs to set DISPLAY env for LG_B1_Client_input be able to + # start at boot. + export DISPLAY=:0 + /opt/lg/bin/LG_B1_Client_input & +} + +function balloon_civ() +{ + #Balloon guest memory to 2048M on boot + if [ ! -z ${ENABLE_CIV_BALLOON} ]; then + /opt/cfc/mwc/bin/balloon_guest.sh 2048 + fi +} -# needs to set DISPLAY env for LG_B1_Client_input be able to -# start at boot. -export DISPLAY=:0 -/opt/lg/bin/LG_B1_Client_input & +function pause_civ() +{ + if [ -z "$(pidof mwc_launcher)" ] && [ -z "$(pgrep -ax adb | grep -v "fork-server")" ] && [ -z "$(pidof startapp)" ]; then + # Pause CiV + /opt/cfc/mwc/bin/pause_civ.sh + # Kill adb server for power saving + adb kill-server + fi +} -# monitor share folder -/bin/bash /etc/sharefolder_monitor.sh & +#----------------- Main Process started from here -------------------- sleep 10 +is_civ_ready || exit -1 + +${CIV_PATH}/scripts/stream & + +launch_lg_input_client + +/etc/sharefolder_monitor.sh & + +balloon_civ + /opt/lg/bin/LG_B1_Client_clipboard guestClipboard:enable=true & -#Balloon guest memory to 2048M on boot -if [ ! -z ${ENABLE_CIV_BALLOON} ]; then - /opt/cfc/mwc/bin/balloon_guest.sh 2048 -fi - -#wait for android ready -sleep 20 -# Pause CiV -if [ -z "$(pidof mwc_launcher)" ] && [ -z "$(pgrep -ax adb | grep -v "fork-server")" ]; then - /opt/cfc/mwc/bin/pause_civ.sh -fi +pause_civ exit 0 diff --git a/host/src/pack/dpkg/etc/sharefolder_monitor.sh b/host/src/pack/dpkg/etc/sharefolder_monitor.sh old mode 100644 new mode 100755 index 079f085..0b9e065 --- a/host/src/pack/dpkg/etc/sharefolder_monitor.sh +++ b/host/src/pack/dpkg/etc/sharefolder_monitor.sh @@ -3,8 +3,8 @@ MONITOR_FOLDER_1=$HOME"/Android/Download" MONITOR_FOLDER_2=$HOME"/Android/Pictures" -FOLDER_1_UPDATE='adb shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/Download' -FOLDER_2_UPDATE='adb shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/Pictures' +FOLDER_1_UPDATE='adb -s vsock:3:5555 shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/Download' +FOLDER_2_UPDATE='adb -s vsock:3:5555 shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/Pictures' function folder_notify() { diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/api_test b/host/src/pack/dpkg/opt/cfc/mwc/bin/api_test index 2175353..587ba1a 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/bin/api_test and b/host/src/pack/dpkg/opt/cfc/mwc/bin/api_test differ diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/lg_launcher.sh b/host/src/pack/dpkg/opt/cfc/mwc/bin/lg_launcher.sh index 10b9be9..d850d92 100755 --- a/host/src/pack/dpkg/opt/cfc/mwc/bin/lg_launcher.sh +++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/lg_launcher.sh @@ -1,6 +1,8 @@ #!/bin/bash NUM_PARAMS=$# +FOLDER_1_UPDATE='adb -s vsock:3:5555 shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/Download' +FOLDER_2_UPDATE='adb -s vsock:3:5555 shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/emulated/0/Pictures' if [ "$NUM_PARAMS" -lt "2" ]; then @@ -8,18 +10,16 @@ then exit 1 fi -# Resume CiV -/opt/cfc/mwc/bin/resume_civ.sh - num_start_app=`ps aux | grep startapp | grep -v grep | wc -l` if [ "$num_start_app" -lt "1" ]; then - /opt/cfc/mwc/bin/resume_civ.sh - if [ "$(adb get-state | grep "device" | awk '{print $1}')" != "device" ]; + if ! systemctl --user is-active civ ; then /opt/lg/bin/startapp fi + # Resume CiV + /opt/cfc/mwc/bin/resume_civ.sh else exit 1 fi @@ -37,6 +37,8 @@ then previous_app=`/opt/cfc/mwc/bin/msg_agent localhost 3000 GET_APP_LASTOPENED | grep "appname" | grep -v grep | sed 's/^appname: *\(.*\),.*$/\1/g'` fi +$FOLDER_1_UPDATE +$FOLDER_2_UPDATE /opt/cfc/mwc/bin/mwc_launcher localhost 3000 $@ echo "appname:$1, previous_app:$previous_app" diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/msg_agent b/host/src/pack/dpkg/opt/cfc/mwc/bin/msg_agent index 079637d..9cfaaef 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/bin/msg_agent and b/host/src/pack/dpkg/opt/cfc/mwc/bin/msg_agent differ diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc index fb1f844..6e6c534 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc and b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc differ diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon index 6db2b1b..40ef472 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon and b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon differ diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_launcher b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_launcher index b0ac36f..1952ba2 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_launcher and b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_launcher differ diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/pause_civ.sh b/host/src/pack/dpkg/opt/cfc/mwc/bin/pause_civ.sh index 390fdd1..9db570e 100755 --- a/host/src/pack/dpkg/opt/cfc/mwc/bin/pause_civ.sh +++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/pause_civ.sh @@ -54,10 +54,18 @@ function pause_civ() { echo "Send QMP: stop" local out + local i echo "{ \"execute\": \"stop\"}" >&4 - read -u 5 -t 1 -r out && echo "OUTPUT: $out" - read -u 5 -t 1 -r out && echo "OUTPUT: $out" + for i in {0..9}; do + read -u 5 -t 1 -r out + echo "OUTPUT: $out" + if [[ ${#out} -eq 15 && "${out:0:14}" == '{"return": {}}' ]]; then + return 0 + fi + done + echo "Failed to Pause CiV!" + return -1 } connect_qmp || exit -1 -pause_civ +pause_civ || exit -1 diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/penguin-peak.ini b/host/src/pack/dpkg/opt/cfc/mwc/bin/penguin-peak.ini index 49cdfb2..c967792 100644 --- a/host/src/pack/dpkg/opt/cfc/mwc/bin/penguin-peak.ini +++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/penguin-peak.ini @@ -8,7 +8,7 @@ path=/usr/bin/qemu-system-x86_64 size=4G [vcpu] -num=2 +num=4 [firmware] type=unified diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/resume_civ.sh b/host/src/pack/dpkg/opt/cfc/mwc/bin/resume_civ.sh index f7ebe89..80bb15a 100755 --- a/host/src/pack/dpkg/opt/cfc/mwc/bin/resume_civ.sh +++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/resume_civ.sh @@ -54,10 +54,18 @@ function resume_civ() { echo "Send QMP: cont" local out + local i echo "{ \"execute\": \"cont\"}" >&4 - read -u 5 -t 1 -r out && echo "OUTPUT: $out" - read -u 5 -t 1 -r out && echo "OUTPUT: $out" + for i in {0..9}; do + read -u 5 -t 1 -r out + echo "OUTPUT: $out" + if [[ ${#out} -eq 15 && "${out:0:14}" == '{"return": {}}' ]]; then + return 0 + fi + done + echo "Failed to resume CiV!" + return -1 } connect_qmp || exit -1 -resume_civ +resume_civ || exit -1 diff --git a/host/src/pack/dpkg/opt/cfc/mwc/lib/libkydroid.so b/host/src/pack/dpkg/opt/cfc/mwc/lib/libkydroid.so index 1f3a54d..8fb933a 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/lib/libkydroid.so and b/host/src/pack/dpkg/opt/cfc/mwc/lib/libkydroid.so differ diff --git a/host/src/pack/pack-cfc.sh b/host/src/pack/pack-cfc.sh index f33a330..cf35d67 100755 --- a/host/src/pack/pack-cfc.sh +++ b/host/src/pack/pack-cfc.sh @@ -3,7 +3,6 @@ cp ../pghost/mwc_hostdaemon dpkg/opt/cfc/mwc/bin/mwc_hostdaemon cp ../pghost/mwc_launcher dpkg/opt/cfc/mwc/bin/mwc_launcher cp ../pghost/loadapp.sh dpkg/opt/cfc/mwc/bin/loadapp.sh cp ../pghost/killapp.sh dpkg/opt/cfc/mwc/bin/killapp.sh -cp ../pghost/lg_launcher.sh dpkg/opt/cfc/mwc/bin/lg_launcher.sh cp ../pghost/closeapp.sh dpkg/opt/cfc/mwc/bin/closeapp.sh cp ../pghost/api_test dpkg/opt/cfc/mwc/bin/api_test cp ../pghost/libkydroid.so dpkg/opt/cfc/mwc/lib/libkydroid.so diff --git a/host/src/pghost/connmgr.cpp b/host/src/pghost/connmgr.cpp index 843bff1..b98ab4a 100644 --- a/host/src/pghost/connmgr.cpp +++ b/host/src/pghost/connmgr.cpp @@ -219,6 +219,7 @@ void* Connmgr::conn_loop (void* data) // TODO: broadcast the socket closed message. cout << "Read from socket returns: " << read_counts << ", close the connection." << endl; connmgr->running = 0; + connmgr->NotifyConnectionClose(); } } return 0; diff --git a/host/src/pghost/lg_launcher.sh b/host/src/pghost/lg_launcher.sh deleted file mode 100755 index 204baf9..0000000 --- a/host/src/pghost/lg_launcher.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -NUM_PARAMS=$# - -if [ "$NUM_PARAMS" -lt "2" ]; -then - echo "Usage: lg_launcher.sh [app icon label]" - exit 1 -fi - -num_start_app=`ps aux | grep startapp | grep -v grep | wc -l` - -if [ "$num_start_app" -lt "1" ]; -then - if [ "$(adb get-state | grep "device" | awk '{print $1}')" != "device" ]; - then - /opt/lg/bin/startapp - fi -else - exit 1 -fi - -# Balloon Guest memory to 4096MB -if [ ! -z ${ENABLE_CIV_BALLOON} ]; then - /opt/cfc/mwc/bin/balloon_guest.sh 4096 -fi - -num_lg_insts=`ps aux | grep LG_B1_Client.*looking-glass | grep -v guestClipboard.*enable.*true | grep -v grep | wc -l` -previous_app="" - -if [ ! "$num_lg_insts" -lt "1" ]; -then - previous_app=`/opt/cfc/mwc/bin/msg_agent localhost 3000 GET_APP_LASTOPENED | grep "appname" | grep -v grep | sed 's/^appname: *\(.*\),.*$/\1/g'` -fi - -# Resume CiV -/opt/cfc/mwc/bin/resume_civ.sh - -/opt/cfc/mwc/bin/mwc_launcher localhost 3000 $@ - -echo "appname:$1, previous_app:$previous_app" - -new_app="$1" - -if [ ! -z "$previous_app" ]; -then - if [ "$new_app" != "$previous_app" ]; - then - echo "Close previous opened app: $previous_app" - adb -s vsock:3:5555 shell am force-stop $previous_app - else - echo "Open same app, do nothing." - fi -fi - -# Balloon Guest memory to 2048MB if no mwc_launcher live -if [ ! -z ${ENABLE_CIV_BALLOON} ]; then - if [ -z $(pidof mwc_launcher) ]; then - /opt/cfc/mwc/bin/balloon_guest.sh 2048 - fi -fi - -# Pause CiV -if [ -z $(pidof mwc_launcher) ]; then - /opt/cfc/mwc/bin/pause_civ.sh -fi - -exit 0 - diff --git a/host/src/pghost/vatclidaemon.cpp b/host/src/pghost/vatclidaemon.cpp index 2ab9934..e9a0fb6 100644 --- a/host/src/pghost/vatclidaemon.cpp +++ b/host/src/pghost/vatclidaemon.cpp @@ -276,7 +276,24 @@ int main (int argc, char **argv) (!(epoll_events[i].events & EPOLLIN))) { cout << "epoll error, i: " << i << " fd: " << epoll_events[i].data.fd << endl; - close(epoll_events[i].data.fd); + int data_error_fd = epoll_events[i].data.fd; + if (clients.find(data_error_fd) != clients.end()) { + VatClient* vatclient = clients.at(data_error_fd); + cout << "Remove the scoket fd: " << data_error_fd << " client: " << static_cast (vatclient) << endl; + clients.erase(data_error_fd); + vatclient->CleanUp(); + delete vatclient; + } + cout << "Remove the socket fd: " << data_error_fd << " from the epoll list." << endl; + int ret = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, data_error_fd, NULL); + if (ret >= 0) { + cout << "Removed the error socket fd from epoll: " << data_error_fd << endl; + } + else { + cout << "Error to remove error scoket fd from epoll fds: " << data_error_fd << " return: " << ret << endl; + } + close (data_error_fd); + continue; } else if(listenfd == epoll_events[i].data.fd) diff --git a/host/src/pghost/vatclient.cpp b/host/src/pghost/vatclient.cpp index e4b9076..ffb5071 100644 --- a/host/src/pghost/vatclient.cpp +++ b/host/src/pghost/vatclient.cpp @@ -258,6 +258,9 @@ int VatClient::HandleEventSingleLG(Event* event) case EVENT_NOTIFY_LG_APP_CLOSED: running = 0; break; + case EVENT_CONNECTION_CLOSED: + running = 0; + break; default: break; } @@ -497,6 +500,7 @@ void VatClient::CleanUp() // Stop the instance and free the resources. m_launcherconnmgr->connDown(); running = 0; + m_eventqueue->awaken(); pthread_join (m_client_loop, NULL); delete m_eventqueue; delete m_launcherconnmgr;