Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified host/bins/cfc-0.1.0-x64.deb
Binary file not shown.
2 changes: 1 addition & 1 deletion host/src/pack/dpkg/etc/rc.civ
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ then
if [ -f /opt/cfc/mwc/bin/wakelock_check ]
then
echo "Start wakelock check script" >> $TEMP_LOG
/opt/cfc/mwc/bin/wakelock_check &
/opt/cfc/mwc/bin/wakelock_check &
fi

if [ ! -f $HOME/.intel/.civ/penguin-peak.ini ]
Expand Down
110 changes: 110 additions & 0 deletions host/src/pack/dpkg/opt/cfc/mwc/bin/condition_resume_civ.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

INPUT=$(mktemp -u) || exit -1
OUTPUT=$(mktemp -u) || exit -1
#QMP_PATH=$(realpath ~/.intel/.civ/.penguin-peak.qmp.unix.socket)
echo "Called in condition_resume_civ.sh"

QEMU_PID=`pidof qemu-system-x86_64`
if [ -z "$QEMU_PID" ];
then
echo "Qemu process doesn't exit, skip."
exit 0
fi

#QMP_PATH=$(realpath /proc/$QEMU_PID/cwd/.intel/.civ/.penguin-peak.qmp.unix.socket)
USERNAME=`ps --no-headers -o euser -p $QEMU_PID`
QMP_PATH=$(realpath /home/$USERNAME/.intel/.civ/.penguin-peak.qmp.unix.socket)
echo "QMP_PATH:$QMP_PATH"

function clean_up()
{
exec 4<&-
exec 5<&-
[[ ! -z $INPUT && -f $INPUT ]] && rm $INPUT
[[ ! -z $OUTPUT && -f $OUTPUT ]] && rm $OUTPUT
}
trap clean_up EXIT

function connect_qmp()
{
local attempts=0
while ! nc -z -U "$QMP_PATH"; do
sleep 0.1
(( attempts++ ))
if ((attempts == 100)); then
echo "Error: QMP Socket is not ready yet!"
return -1
fi
done

mkfifo "$INPUT" || exit -1
mkfifo "$OUTPUT" || exit -1
(cat "$INPUT" | nc -U "$QMP_PATH" > "$OUTPUT") &
exec 4> "$INPUT"
exec 5< "$OUTPUT"

local out
read -u 5 -r out;
echo "Socket connected: $out"
if ! grep -q "{.*QMP.*version.*qemu.*package.*capabilities.*}" <<< "$out"; then
return -1
fi

echo "Send: qmp_capabilities"
echo '{ "execute": "qmp_capabilities" }' >&4
read -u 5 -r out
echo "QMP Capabilities: $out"
if [[ ${#out} -eq 15 && "${out:0:14}" == '{"return": {}}' ]]; then
echo "QMP connected!"
else
echo "Failed to connect QMP!"
return -1
fi
}

function resume_civ()
{
echo "Send QMP: cont"
local out
local i
echo "{ \"execute\": \"cont\"}" >&4
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
}

function toggle_status()
{
echo "Send QMP: toggle_instance_status, value=1"
local out
echo "{ \"execute\": \"toggle_instance_status\", \"arguments\": { \"value\": 1 } }" >&4
read -u 5 -t 1 -r out && echo "OUTPUT: $out"
}

function resume_civ_in_bg()
{
#sleep 2
connect_qmp || exit -1
resume_civ || exit -1
toggle_status
echo "Civ resumed."
}

num_lg_insts=`ps aux | grep LG_B1_Client.*looking-glass | grep -v guestClipboard.*enable.*true | grep -v grep | wc -l`

if [ ! "$num_lg_insts" -lt "1" ] || [ ! -z "$(pidof mwc_launcher)" ] || [ ! -z "$(pgrep -ax adb | grep -v "fork-server")" ];
then
echo "Try to resume civ since there are opened apps..."
resume_civ_in_bg
else
echo "No app is opening, skip the civ resume."
fi


85 changes: 85 additions & 0 deletions host/src/pack/dpkg/opt/cfc/mwc/bin/force_pause_civ.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

INPUT=$(mktemp -u) || exit -1
OUTPUT=$(mktemp -u) || exit -1
#QMP_PATH=$(realpath ~/.intel/.civ/.penguin-peak.qmp.unix.socket)
QEMU_PID=`pidof qemu-system-x86_64`

if [ -z "$QEMU_PID" ];
then
echo "Qemu process doesn't exit, skip."
exit 0
fi

#QMP_PATH=$(realpath /proc/$QEMU_PID/cwd/.intel/.civ/.penguin-peak.qmp.unix.socket)
USERNAME=`ps --no-headers -o euser -p $QEMU_PID`
QMP_PATH=$(realpath /home/$USERNAME/.intel/.civ/.penguin-peak.qmp.unix.socket)
echo "QMP_PATH:$QMP_PATH"

function clean_up()
{
exec 4<&-
exec 5<&-
[[ ! -z $INPUT && -f $INPUT ]] && rm $INPUT
[[ ! -z $OUTPUT && -f $OUTPUT ]] && rm $OUTPUT
}
trap clean_up EXIT

function connect_qmp()
{
local attempts=0
while ! nc -z -U "$QMP_PATH"; do
sleep 0.1
(( attempts++ ))
if ((attempts == 100)); then
echo "Error: QMP Socket is not ready yet!"
return -1
fi
done

mkfifo "$INPUT" || exit -1
mkfifo "$OUTPUT" || exit -1
(cat "$INPUT" | nc -U "$QMP_PATH" > "$OUTPUT") &
exec 4> "$INPUT"
exec 5< "$OUTPUT"

local out
read -u 5 -r out;
echo "Socket connected: $out"
if ! grep -q "{.*QMP.*version.*qemu.*package.*capabilities.*}" <<< "$out"; then
return -1
fi

echo "Send: qmp_capabilities"
echo '{ "execute": "qmp_capabilities" }' >&4
read -u 5 -r out
echo "QMP Capabilities: $out"
if [[ ${#out} -eq 15 && "${out:0:14}" == '{"return": {}}' ]]; then
echo "QMP connected!"
else
echo "Failed to connect QMP!"
return -1
fi
}

function pause_civ()
{
echo "Send QMP: stop"
local out
local i
echo "{ \"execute\": \"stop\"}" >&4
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 || exit -1
echo "Pause CIV executed."
16 changes: 16 additions & 0 deletions host/src/pack/dpkg/opt/cfc/mwc/bin/inhibit_lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

# Inhibit Gnome-SessionManager screen off on idle

import dbus
import sys
import time
INHIBIT_IDLE = 8
max_time = 4294967295
bus = dbus.SessionBus()

session = bus.get_object(bus_name='org.gnome.SessionManager',
object_path='/org/gnome/SessionManager')
session_interface = dbus.Interface(session, dbus_interface='org.gnome.SessionManager')
session_interface.Inhibit("idle Inhibit", 0, "User requested blank screen inhibited in idle", INHIBIT_IDLE)
time.sleep(max_time)
1 change: 0 additions & 1 deletion host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ then
fi

adb -s vsock:3:5555 shell am force-stop $1
adb -s vsock:3:5555 shell am force-stop com.android.packageinstaller

exit 0

4 changes: 3 additions & 1 deletion host/src/pack/dpkg/opt/cfc/mwc/bin/lg_launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ fi
# Needs to restart civ if this happens to ensure all required services are
# up and running
num_lg_input=`ps aux | grep LG_B1_Client_input | grep -v grep | wc -l`
num_start_app=`ps aux | grep startapp | grep -v grep | wc -l`

if [ "$num_lg_input" -lt "1" ];
# Check if startapp is already running to avoid stop/start too frequent.
if [ "$num_lg_input" -lt "1" ] && [ "$num_start_app" -lt "1" ];
then
systemctl --user stop civ
systemctl --user start civ &
Expand Down
7 changes: 6 additions & 1 deletion host/src/pack/dpkg/opt/cfc/mwc/bin/loadapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ function configure_wm_density()

configure_wm_density

adb -s vsock:3:5555 shell am start -W -S -n $2 --display $3 --activity-no-animation
if [ "$1" = "com.tencent.mm" ];
then
adb -s vsock:3:5555 shell am start -W -S -n $2 --display $3 --activity-no-animation
else
adb -s vsock:3:5555 shell am start -S -n $2 --display $3 --activity-no-animation
fi

if [[ $"NUM_PARAMS" -ge "4" ]];
then
Expand Down
Binary file modified host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon
Binary file not shown.
45 changes: 24 additions & 21 deletions host/src/pack/dpkg/opt/cfc/mwc/bin/wakelock_check
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
#! /bin/sh
run_inhibit=0
while true
do
if echo "$(systemctl --user is-active civ | grep -w 'active')" && [ "$(pidof mwc_launcher)" ] && [ "$(pidof LG_B1_Client)" ]
then
if adb get-state 1>/dev/null 2>&1
then
state=$(adb shell dumpsys power | grep -oE 'SCREEN_BRIGHT_WAKE_LOCK')
if echo "$state" | grep 'SCREEN_BRIGHT_WAKE_LOCK'; then
if echo "$(gsettings get org.ukui.screensaver idle-activation-enabled)" | grep 'true'; then
set_by_script='true'
echo "$(gsettings set org.ukui.screensaver idle-activation-enabled false)"
fi
else
if [ $set_by_script = 'true' ]
then
echo "$(gsettings reset org.ukui.screensaver idle-activation-enabled)"
set_by_script='false'
fi
fi
fi
if adb get-state 1>/dev/null 2>&1
then
state=$(adb shell dumpsys power | grep -oE 'SCREEN_BRIGHT_WAKE_LOCK')
if echo "$state" | grep 'SCREEN_BRIGHT_WAKE_LOCK'; then
if [ $run_inhibit = 0 ]
then
python3 /opt/cfc/mwc/bin/inhibit_lock &
run_inhibit=1
proc_pid=$!
fi
else
if [ $proc_pid ]; then
kill $proc_pid
unset proc_pid
run_inhibit=0
fi
fi
fi
else
if [ $set_by_script = 'true' ]
then
echo "$(gsettings reset org.ukui.screensaver idle-activation-enabled)"
set_by_script='false'
fi
if [ $proc_pid ]; then
kill $proc_pid
unset proc_pid
run_inhibit=0
fi
fi
sleep 50
done
10 changes: 10 additions & 0 deletions host/src/pack/dpkg/usr/lib/systemd/system-sleep/civ-switch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

case $1 in
pre)
/opt/cfc/mwc/bin/force_pause_civ.sh
;;
post)
/opt/cfc/mwc/bin/condition_resume_civ.sh
;;
esac
2 changes: 1 addition & 1 deletion host/src/pghost/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ all: mwc_launcher mwc_hostdaemon mwc libkydroid.so api_test msg_agent comm_host_


MWCHOSTDAEMONSRCS = vatclidaemon.cpp connsock.cpp connfactory.cpp connmgr.cpp \
eventqueue.cpp utils.cpp vatclient.cpp
eventqueue.cpp utils.cpp vatclient.cpp lgslot.cpp

MWCLAUNCHERSRCS = vatlauncher.cpp lgclient.cpp connfactory.cpp connmgr.cpp eventqueue.cpp \
connsock.cpp utils.cpp ShortcutMgrLg.cpp Log.cpp AdbProxy.cpp
Expand Down
Loading