diff --git a/host/bins/cfc-0.1.0-x64.deb b/host/bins/cfc-0.1.0-x64.deb
index 09fa3d4..48c1e00 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 4bb2ab4..dbe8178 100755
--- a/host/src/pack/dpkg/etc/rc.civ
+++ b/host/src/pack/dpkg/etc/rc.civ
@@ -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 ]
diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/inhibit_lock b/host/src/pack/dpkg/opt/cfc/mwc/bin/inhibit_lock
new file mode 100755
index 0000000..e4a91a4
--- /dev/null
+++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/inhibit_lock
@@ -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)
diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh b/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh
index ccb3f6c..ca100dc 100755
--- a/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh
+++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh
@@ -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
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 9182064..7c7fdce 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
@@ -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 &
diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/loadapp.sh b/host/src/pack/dpkg/opt/cfc/mwc/bin/loadapp.sh
index 4e1f437..89ce37f 100755
--- a/host/src/pack/dpkg/opt/cfc/mwc/bin/loadapp.sh
+++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/loadapp.sh
@@ -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
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 e29758c..0df5605 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/wakelock_check b/host/src/pack/dpkg/opt/cfc/mwc/bin/wakelock_check
index 13859be..de8dbaf 100755
--- a/host/src/pack/dpkg/opt/cfc/mwc/bin/wakelock_check
+++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/wakelock_check
@@ -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
diff --git a/host/src/pghost/Makefile b/host/src/pghost/Makefile
index bc920f6..26c47d4 100644
--- a/host/src/pghost/Makefile
+++ b/host/src/pghost/Makefile
@@ -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
diff --git a/host/src/pghost/lgslot.cpp b/host/src/pghost/lgslot.cpp
new file mode 100644
index 0000000..99ba313
--- /dev/null
+++ b/host/src/pghost/lgslot.cpp
@@ -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 .
+
+SPDX-License-Identifier: GPL-3.0-or-later
+*/
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#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; islot_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;
+}
diff --git a/host/src/pghost/lgslot.h b/host/src/pghost/lgslot.h
new file mode 100644
index 0000000..3d92e7a
--- /dev/null
+++ b/host/src/pghost/lgslot.h
@@ -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 .
+
+SPDX-License-Identifier: GPL-3.0-or-later
+*/
+
+#ifndef __LGSLOT_H__
+#define __LGSLOT_H__
+#include
+using namespace std;
+
+#include
+#include
+
+#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
diff --git a/host/src/pghost/vatclidaemon.cpp b/host/src/pghost/vatclidaemon.cpp
index ef81772..7bccb67 100644
--- a/host/src/pghost/vatclidaemon.cpp
+++ b/host/src/pghost/vatclidaemon.cpp
@@ -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;
@@ -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) {
@@ -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;
@@ -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;
@@ -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);
}
diff --git a/host/src/pghost/vatclient.cpp b/host/src/pghost/vatclient.cpp
index 3ab3bc7..368f399 100644
--- a/host/src/pghost/vatclient.cpp
+++ b/host/src/pghost/vatclient.cpp
@@ -39,12 +39,13 @@ Date: 2021.04.27
#include "common.h"
#include "connmgr.h"
-
+#include "lgslot.h"
using namespace std;
VatClient::VatClient()
{
+ slot_id = -1;
}
VatClient::~VatClient()
@@ -101,6 +102,11 @@ void VatClient::set_lg_slots(lgslot_t** slots)
m_lg_slots = slots;
}
+void VatClient::set_lgslot_inst(LGSlot* lgslot)
+{
+ m_lgslot = lgslot;
+}
+
extern int get_event_id_by_name (char* evt_name);
extern int get_key_value (char* src, char* key, char* ret_buf, char* kv_separtor, char* key_separator);
void VatClient::EnQueueGlobalEvt (char* buf)
@@ -359,8 +365,9 @@ int VatClient::HandleEvent(Event* event)
}
printf("slot_found: %d, idle_slot: %d\n", slot_found, idle_slot);
if (slot_found > -1) {
- slot_id = slot_found;
- // Send the slot of the launched app to client
+ // Don't set slot_id in EVENT_REQ_CHECK_IF_APP_LAUNCHED, otherwise it may cause exisitng launched app state messed.
+ //slot_id = slot_found;
+ // Send the slot of the launched app to client
snprintf (lgslot_body, sizeof(lgslot_body), "{lg_instance_id=%d;}", slot_found);
char msg_body[512];
compose_msg_body(msg_body, sizeof(msg_body), EVENT_RES_CHECK_IF_APP_LAUNCHED, lgslot_body);
@@ -388,18 +395,10 @@ int VatClient::HandleEvent(Event* event)
}
break;
case EVENT_REQ_GET_IDLE_LG_SLOT:
- idle_slot = -1;
- for (int i=0; islot_status) {
- printf("found one idle slot:%d and set the slot as reserved\n", i);
- idle_slot = i;
- slot_id = idle_slot;
- m_lg_slots[i]->slot_status = LGSLOT_RESERVED;
- break;
- }
- }
+ idle_slot = m_lgslot->ReserveOneLGSlot();
printf("idle_slot:%d\n", idle_slot);
- if (idle_slot > -1) {
+ if (idle_slot >=0 && idle_slot < NUM_LG_SLOTS) {
+ slot_id = idle_slot;
snprintf (lgslot_body, sizeof(lgslot_body), "{lg_instance_id=%d,};", idle_slot);
char msg_body[512];
compose_msg_body(msg_body, sizeof(msg_body), EVENT_RES_IDEL_LG_SLOT, lgslot_body);
@@ -429,11 +428,11 @@ int VatClient::HandleEvent(Event* event)
(char*) "=",
(char*) ",");
lg_slot = atoi(lg_instance_id);
- if (lg_slot < NUM_LG_SLOTS) {
- m_lg_slots[lg_slot]->slot_status = LGSLOT_USED;
- slot_id = lg_slot;
- snprintf(m_lg_slots[lg_slot]->appname, sizeof(m_lg_slots[lg_slot]->appname), "%s", appname);
- snprintf(m_lg_slots[lg_slot]->activity, sizeof(m_lg_slots[lg_slot]->activity), "%s", activity);
+ if (lg_slot < NUM_LG_SLOTS && lg_slot >=0) {
+ int ret = m_lgslot->BundleLGSlotApp(lg_slot, appname, activity);
+ if (ret >=0) {
+ slot_id = lg_slot;
+ }
}
for (int i=0; islot_status, m_lg_slots[i]->appname, m_lg_slots[i]->activity);
@@ -450,9 +449,7 @@ int VatClient::HandleEvent(Event* event)
if (LGSLOT_USED == m_lg_slots[i]->slot_status) {
char* launched_appname = m_lg_slots[i]->appname;
if (strstr(launched_appname, appname)) {
- m_lg_slots[i]->slot_status = LGSLOT_IDLE;
- memset(m_lg_slots[i]->appname, 0, sizeof(m_lg_slots[i]->appname));
- memset(m_lg_slots[i]->activity, 0, sizeof(m_lg_slots[i]->activity));
+ m_lgslot->SetLGSlotIdle(i);
kill_lg_process = 1;
slot_found = i;
break;
@@ -535,9 +532,7 @@ int VatClient::HandleEvent(Event* event)
(char*) ";");
lg_slot = atoi(lg_instance_id);
if (lg_slot >=0 && lg_slot < NUM_LG_SLOTS) {
- m_lg_slots[lg_slot]->slot_status = LGSLOT_IDLE;
- memset(m_lg_slots[lg_slot]->appname, 0, sizeof(m_lg_slots[lg_slot]->appname));
- memset(m_lg_slots[lg_slot]->activity, 0, sizeof(m_lg_slots[lg_slot]->activity));
+ m_lgslot->SetLGSlotIdle(lg_slot);
}
running = 0;
break;
@@ -600,9 +595,7 @@ void VatClient::CleanUp()
if (slot_id >=0 && slot_id < NUM_LG_SLOTS) {
if (LGSLOT_USED == m_lg_slots[slot_id]->slot_status) {
- m_lg_slots[slot_id]->slot_status = LGSLOT_IDLE;
- memset(m_lg_slots[slot_id]->appname, 0, sizeof(m_lg_slots[slot_id]->appname));
- memset(m_lg_slots[slot_id]->activity, 0, sizeof(m_lg_slots[slot_id]->activity));
+ m_lgslot->SetLGSlotIdle(slot_id);
}
}
}
diff --git a/host/src/pghost/vatclient.h b/host/src/pghost/vatclient.h
index 435f84b..a55eb19 100644
--- a/host/src/pghost/vatclient.h
+++ b/host/src/pghost/vatclient.h
@@ -28,6 +28,7 @@ class EventQueue;
class PipeMgr;
class Event;
class Connmgr;
+class LGSlot;
#include "common.h"
@@ -42,6 +43,7 @@ class VatClient
void readAndParseEvt();
bool needRelease();
void set_lg_slots(lgslot_t** slots);
+ void set_lgslot_inst(LGSlot* lgslot);
int getLGSlotID();
void Close();
char* getAppname();
@@ -65,6 +67,7 @@ class VatClient
pthread_t m_client_loop = 0;
volatile int slot_id = -1;
lgslot_t** m_lg_slots = NULL;
+ LGSlot* m_lgslot = NULL;
std::string m_appname;
std::string m_activity;
};