Skip to content
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
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
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
107 changes: 107 additions & 0 deletions host/src/pghost/lgslot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright (C) 2021 Intel Corporation

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

#include <sys/types.h>
#include <pthread.h>

#include "lgslot.h"
#include "common.h"

LGSlot::LGSlot ()
{
if (pthread_mutex_init (&m_slots_lock, 0)) {
printf("LGSlot, error to init slots lock!\n");
}
}

LGSlot::~LGSlot()
{
if (pthread_mutex_destroy(&m_slots_lock)) {
printf("~LGSlot, error to destroy slots lock!\n");
}
}
void LGSlot::SetLGSlots(lgslot_t** slots)
{
m_lg_slots = slots;
}

int LGSlot::SetLGSlotIdle(int lgslot_id)
{
if (NULL == m_lg_slots) {
return -1;
}

if (lgslot_id >=0 && lgslot_id < NUM_LG_SLOTS) {
pthread_mutex_lock(&m_slots_lock);
m_lg_slots[lgslot_id]->slot_status = LGSLOT_IDLE;
memset(m_lg_slots[lgslot_id]->appname, 0, sizeof(m_lg_slots[lgslot_id]->appname));
memset(m_lg_slots[lgslot_id]->activity, 0, sizeof(m_lg_slots[lgslot_id]->activity));
pthread_mutex_unlock(&m_slots_lock);
}
else {
return -1;
}

return lgslot_id;
}

int LGSlot::BundleLGSlotApp(int lgslot_id, char* appname, char* activity)
{
if (NULL == m_lg_slots) {
return -1;
}

if (lgslot_id >= 0 && lgslot_id < NUM_LG_SLOTS) {
pthread_mutex_lock(&m_slots_lock);
m_lg_slots[lgslot_id]->slot_status = LGSLOT_USED;
snprintf(m_lg_slots[lgslot_id]->appname, sizeof(m_lg_slots[lgslot_id]->appname), "%s", appname);
snprintf(m_lg_slots[lgslot_id]->activity, sizeof(m_lg_slots[lgslot_id]->activity), "%s", activity);
pthread_mutex_unlock(&m_slots_lock);
}
else {
return -1;
}

return lgslot_id;
}

int LGSlot::ReserveOneLGSlot()
{
if (NULL == m_lg_slots) {
return -1;
}

int idle_slot = -1;
pthread_mutex_lock(&m_slots_lock);
for (int i=0; i<NUM_LG_SLOTS; i++) {
if (LGSLOT_IDLE == m_lg_slots[i]->slot_status) {
printf("found one idle slot:%d and set the slot as reserved\n", i);
idle_slot = i;
m_lg_slots[i]->slot_status = LGSLOT_RESERVED;
break;
}
}
pthread_mutex_unlock(&m_slots_lock);
return idle_slot;
}
45 changes: 45 additions & 0 deletions host/src/pghost/lgslot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright (C) 2021 Intel Corporation

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef __LGSLOT_H__
#define __LGSLOT_H__
#include <pthread.h>
using namespace std;

#include <stdio.h>
#include <stdlib.h>

#include "common.h"

class LGSlot {
public:
LGSlot ();
void SetLGSlots(lgslot_t** slots);
int SetLGSlotIdle(int lgslot_id);
int BundleLGSlotApp(int lgslot_id, char* appname, char* activity);
int ReserveOneLGSlot();
~LGSlot();
private:
//Slot array lock protection;
pthread_mutex_t m_slots_lock;
lgslot_t** m_lg_slots = NULL;

};

#endif
26 changes: 18 additions & 8 deletions host/src/pghost/vatclidaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Date: 2021.04.27
#include "eventqueue.h"

#include "vatclient.h"
#include "lgslot.h"

#define LISTENPORT 3001
#define LISTENQ 8
using namespace std;
Expand All @@ -63,6 +65,8 @@ lgslot_t* g_lg_slots[1];
lgslot_t* g_lg_slots[4];
#endif

LGSlot* g_lgslot_inst = NULL;

extern int get_key_value (char* src, char* key, char* ret_buf, char* kv_separtor, char* key_separator);
#ifdef LG_SINGLE_MODE
static int HandleEvent(global_data_t* gdata, Event* event) {
Expand Down Expand Up @@ -129,14 +133,12 @@ static int HandleEvent(global_data_t* gdata, Event* event) {
}
it++;
}
if (lg_slot >=0 && lg_slot < NUM_LG_SLOTS) {
if (strstr(g_lg_slots[lg_slot]->appname, appname) && g_lg_slots[lg_slot]->slot_status != LGSLOT_IDLE) {
g_lg_slots[lg_slot]->slot_status = LGSLOT_IDLE;
memset(g_lg_slots[lg_slot]->appname, 0, sizeof(g_lg_slots[lg_slot]->appname));
memset(g_lg_slots[lg_slot]->activity,0, sizeof(g_lg_slots[lg_slot]->activity));
}
}
}
if (lg_slot >=0 && lg_slot < NUM_LG_SLOTS) {
if (strstr(g_lg_slots[lg_slot]->appname, appname) && g_lg_slots[lg_slot]->slot_status != LGSLOT_IDLE) {
g_lgslot_inst->SetLGSlotIdle(lg_slot);
}
}
}
break;
default:
break;
Expand Down Expand Up @@ -204,6 +206,13 @@ int main (int argc, char **argv)
g_lg_slots[i] = p_lgslot;
}
}
g_lgslot_inst = new LGSlot();
if (NULL == g_lgslot_inst) {
perror("Failed to create Looking Glass slot state management instance. Probably low memory situation, exit!");
exit(1);
}
g_lgslot_inst->SetLGSlots(g_lg_slots);

g_data.eventqueue = new EventQueue();
g_data.clients = &clients;
g_data.running = 1;
Expand Down Expand Up @@ -350,6 +359,7 @@ int main (int argc, char **argv)
vatclient->setLauncherCommSock(fd_req);
vatclient->setGlobalEvtQueue (g_data.eventqueue);
vatclient->set_lg_slots(g_lg_slots);
vatclient->set_lgslot_inst(g_lgslot_inst);
vatclient->Run();
clients.emplace (fd_req, vatclient);
}
Expand Down
Loading