SEBWIN-821: Implemented configuration values for critical and low battery charge thresholds.
This commit is contained in:
parent
8c45af88fb
commit
79dedf12b5
9 changed files with 123 additions and 13 deletions
|
@ -103,7 +103,6 @@ namespace SafeExamBrowser.Client
|
||||||
messageBox = BuildMessageBox();
|
messageBox = BuildMessageBox();
|
||||||
nativeMethods = new NativeMethods();
|
nativeMethods = new NativeMethods();
|
||||||
networkAdapter = new NetworkAdapter(ModuleLogger(nameof(NetworkAdapter)), nativeMethods);
|
networkAdapter = new NetworkAdapter(ModuleLogger(nameof(NetworkAdapter)), nativeMethods);
|
||||||
powerSupply = new PowerSupply(ModuleLogger(nameof(PowerSupply)));
|
|
||||||
runtimeProxy = new RuntimeProxy(runtimeHostUri, new ProxyObjectFactory(), ModuleLogger(nameof(RuntimeProxy)), Interlocutor.Client);
|
runtimeProxy = new RuntimeProxy(runtimeHostUri, new ProxyObjectFactory(), ModuleLogger(nameof(RuntimeProxy)), Interlocutor.Client);
|
||||||
systemInfo = new SystemInfo(registry);
|
systemInfo = new SystemInfo(registry);
|
||||||
taskbar = uiFactory.CreateTaskbar(ModuleLogger("Taskbar"));
|
taskbar = uiFactory.CreateTaskbar(ModuleLogger("Taskbar"));
|
||||||
|
@ -128,6 +127,7 @@ namespace SafeExamBrowser.Client
|
||||||
operations.Enqueue(new ConfigurationOperation(context, logger, runtimeProxy));
|
operations.Enqueue(new ConfigurationOperation(context, logger, runtimeProxy));
|
||||||
operations.Enqueue(new DelegateOperation(UpdateAppConfig));
|
operations.Enqueue(new DelegateOperation(UpdateAppConfig));
|
||||||
operations.Enqueue(new DelegateOperation(BuildIntegrityModule));
|
operations.Enqueue(new DelegateOperation(BuildIntegrityModule));
|
||||||
|
operations.Enqueue(new DelegateOperation(BuildPowerSupply));
|
||||||
operations.Enqueue(new LazyInitializationOperation(BuildClientHostOperation));
|
operations.Enqueue(new LazyInitializationOperation(BuildClientHostOperation));
|
||||||
operations.Enqueue(new ClientHostDisconnectionOperation(context, logger, FIVE_SECONDS));
|
operations.Enqueue(new ClientHostDisconnectionOperation(context, logger, FIVE_SECONDS));
|
||||||
operations.Enqueue(new LazyInitializationOperation(BuildKeyboardInterceptorOperation));
|
operations.Enqueue(new LazyInitializationOperation(BuildKeyboardInterceptorOperation));
|
||||||
|
@ -265,6 +265,11 @@ namespace SafeExamBrowser.Client
|
||||||
context.IntegrityModule = new IntegrityModule(context.AppConfig, ModuleLogger(nameof(IntegrityModule)));
|
context.IntegrityModule = new IntegrityModule(context.AppConfig, ModuleLogger(nameof(IntegrityModule)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BuildPowerSupply()
|
||||||
|
{
|
||||||
|
powerSupply = new PowerSupply(ModuleLogger(nameof(PowerSupply)), context.Settings.PowerSupply);
|
||||||
|
}
|
||||||
|
|
||||||
private IOperation BuildKeyboardInterceptorOperation()
|
private IOperation BuildKeyboardInterceptorOperation()
|
||||||
{
|
{
|
||||||
var keyboardInterceptor = new KeyboardInterceptor(ModuleLogger(nameof(KeyboardInterceptor)), nativeMethods, context.Settings.Keyboard);
|
var keyboardInterceptor = new KeyboardInterceptor(ModuleLogger(nameof(KeyboardInterceptor)), nativeMethods, context.Settings.Keyboard);
|
||||||
|
|
|
@ -20,18 +20,24 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
case Keys.UserInterface.ActionCenter.EnableActionCenter:
|
case Keys.UserInterface.ActionCenter.EnableActionCenter:
|
||||||
MapEnableActionCenter(settings, value);
|
MapEnableActionCenter(settings, value);
|
||||||
break;
|
break;
|
||||||
case Keys.UserInterface.ShowAudio:
|
case Keys.UserInterface.SystemControls.Audio.Show:
|
||||||
MapShowAudio(settings, value);
|
MapShowAudio(settings, value);
|
||||||
break;
|
break;
|
||||||
case Keys.UserInterface.ShowClock:
|
case Keys.UserInterface.SystemControls.Clock.Show:
|
||||||
MapShowClock(settings, value);
|
MapShowClock(settings, value);
|
||||||
break;
|
break;
|
||||||
case Keys.UserInterface.ShowKeyboardLayout:
|
case Keys.UserInterface.SystemControls.KeyboardLayout.Show:
|
||||||
MapShowKeyboardLayout(settings, value);
|
MapShowKeyboardLayout(settings, value);
|
||||||
break;
|
break;
|
||||||
case Keys.UserInterface.ShowNetwork:
|
case Keys.UserInterface.SystemControls.Network.Show:
|
||||||
MapShowNetwork(settings, value);
|
MapShowNetwork(settings, value);
|
||||||
break;
|
break;
|
||||||
|
case Keys.UserInterface.SystemControls.PowerSupply.ChargeThresholdCritical:
|
||||||
|
MapChargeThresholdCritical(settings, value);
|
||||||
|
break;
|
||||||
|
case Keys.UserInterface.SystemControls.PowerSupply.ChargeThresholdLow:
|
||||||
|
MapChargeThresholdLow(settings, value);
|
||||||
|
break;
|
||||||
case Keys.UserInterface.Taskbar.EnableTaskbar:
|
case Keys.UserInterface.Taskbar.EnableTaskbar:
|
||||||
MapEnableTaskbar(settings, value);
|
MapEnableTaskbar(settings, value);
|
||||||
break;
|
break;
|
||||||
|
@ -88,6 +94,22 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapChargeThresholdCritical(AppSettings settings, object value)
|
||||||
|
{
|
||||||
|
if (value is double threshold)
|
||||||
|
{
|
||||||
|
settings.PowerSupply.ChargeThresholdCritical = threshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MapChargeThresholdLow(AppSettings settings, object value)
|
||||||
|
{
|
||||||
|
if (value is double threshold)
|
||||||
|
{
|
||||||
|
settings.PowerSupply.ChargeThresholdLow = threshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void MapEnableTaskbar(AppSettings settings, object value)
|
private void MapEnableTaskbar(AppSettings settings, object value)
|
||||||
{
|
{
|
||||||
if (value is bool enable)
|
if (value is bool enable)
|
||||||
|
|
|
@ -235,6 +235,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
||||||
settings.Mouse.AllowMiddleButton = false;
|
settings.Mouse.AllowMiddleButton = false;
|
||||||
settings.Mouse.AllowRightButton = true;
|
settings.Mouse.AllowRightButton = true;
|
||||||
|
|
||||||
|
settings.PowerSupply.ChargeThresholdCritical = 0.1;
|
||||||
|
settings.PowerSupply.ChargeThresholdLow = 0.2;
|
||||||
|
|
||||||
settings.Proctoring.Enabled = false;
|
settings.Proctoring.Enabled = false;
|
||||||
settings.Proctoring.ForceRaiseHandMessage = false;
|
settings.Proctoring.ForceRaiseHandMessage = false;
|
||||||
settings.Proctoring.JitsiMeet.AllowChat = false;
|
settings.Proctoring.JitsiMeet.AllowChat = false;
|
||||||
|
|
|
@ -334,10 +334,6 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
||||||
|
|
||||||
internal static class UserInterface
|
internal static class UserInterface
|
||||||
{
|
{
|
||||||
internal const string ShowAudio = "audioControlEnabled";
|
|
||||||
internal const string ShowClock = "showTime";
|
|
||||||
internal const string ShowKeyboardLayout = "showInputLanguage";
|
|
||||||
internal const string ShowNetwork = "allowWlan";
|
|
||||||
internal const string UserInterfaceMode = "touchOptimized";
|
internal const string UserInterfaceMode = "touchOptimized";
|
||||||
|
|
||||||
internal static class ActionCenter
|
internal static class ActionCenter
|
||||||
|
@ -345,6 +341,35 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
||||||
internal const string EnableActionCenter = "showSideMenu";
|
internal const string EnableActionCenter = "showSideMenu";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static class SystemControls
|
||||||
|
{
|
||||||
|
internal static class Audio
|
||||||
|
{
|
||||||
|
internal const string Show = "audioControlEnabled";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class Clock
|
||||||
|
{
|
||||||
|
internal const string Show = "showTime";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class KeyboardLayout
|
||||||
|
{
|
||||||
|
internal const string Show = "showInputLanguage";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class Network
|
||||||
|
{
|
||||||
|
internal const string Show = "allowWlan";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class PowerSupply
|
||||||
|
{
|
||||||
|
internal const string ChargeThresholdCritical = "batteryChargeThresholdCritical";
|
||||||
|
internal const string ChargeThresholdLow = "batteryChargeThresholdLow";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static class Taskbar
|
internal static class Taskbar
|
||||||
{
|
{
|
||||||
internal const string EnableTaskbar = "showTaskBar";
|
internal const string EnableTaskbar = "showTaskBar";
|
||||||
|
|
|
@ -72,6 +72,11 @@ namespace SafeExamBrowser.Settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MouseSettings Mouse { get; set; }
|
public MouseSettings Mouse { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All settings related to the power supply.
|
||||||
|
/// </summary>
|
||||||
|
public PowerSupplySettings PowerSupply { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All proctoring-related settings.
|
/// All proctoring-related settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -121,6 +126,7 @@ namespace SafeExamBrowser.Settings
|
||||||
Display = new DisplaySettings();
|
Display = new DisplaySettings();
|
||||||
Keyboard = new KeyboardSettings();
|
Keyboard = new KeyboardSettings();
|
||||||
Mouse = new MouseSettings();
|
Mouse = new MouseSettings();
|
||||||
|
PowerSupply = new PowerSupplySettings();
|
||||||
Proctoring = new ProctoringSettings();
|
Proctoring = new ProctoringSettings();
|
||||||
Security = new SecuritySettings();
|
Security = new SecuritySettings();
|
||||||
Server = new ServerSettings();
|
Server = new ServerSettings();
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
<Compile Include="Service\ServiceSettings.cs" />
|
<Compile Include="Service\ServiceSettings.cs" />
|
||||||
<Compile Include="AppSettings.cs" />
|
<Compile Include="AppSettings.cs" />
|
||||||
<Compile Include="SystemComponents\AudioSettings.cs" />
|
<Compile Include="SystemComponents\AudioSettings.cs" />
|
||||||
|
<Compile Include="SystemComponents\PowerSupplySettings.cs" />
|
||||||
<Compile Include="System\SystemSettings.cs" />
|
<Compile Include="System\SystemSettings.cs" />
|
||||||
<Compile Include="UserInterface\ActionCenterSettings.cs" />
|
<Compile Include="UserInterface\ActionCenterSettings.cs" />
|
||||||
<Compile Include="UserInterface\TaskbarSettings.cs" />
|
<Compile Include="UserInterface\TaskbarSettings.cs" />
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 ETH Zürich, Educational Development and Technology (LET)
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SafeExamBrowser.Settings.SystemComponents
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines all settings for the power supply system component.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
public class PowerSupplySettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The threshold below which the charge of the power supply is to be considered critical.
|
||||||
|
/// </summary>
|
||||||
|
public double ChargeThresholdCritical { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The threshold below which the charge of the power supply is to be considered low.
|
||||||
|
/// </summary>
|
||||||
|
public double ChargeThresholdLow { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using SafeExamBrowser.Logging.Contracts;
|
using SafeExamBrowser.Logging.Contracts;
|
||||||
|
using SafeExamBrowser.Settings.SystemComponents;
|
||||||
using SafeExamBrowser.SystemComponents.Contracts.PowerSupply;
|
using SafeExamBrowser.SystemComponents.Contracts.PowerSupply;
|
||||||
using SafeExamBrowser.SystemComponents.Contracts.PowerSupply.Events;
|
using SafeExamBrowser.SystemComponents.Contracts.PowerSupply.Events;
|
||||||
using PowerLineStatus = System.Windows.Forms.PowerLineStatus;
|
using PowerLineStatus = System.Windows.Forms.PowerLineStatus;
|
||||||
|
@ -18,15 +19,20 @@ namespace SafeExamBrowser.SystemComponents.PowerSupply
|
||||||
{
|
{
|
||||||
public class PowerSupply : IPowerSupply
|
public class PowerSupply : IPowerSupply
|
||||||
{
|
{
|
||||||
|
private readonly ILogger logger;
|
||||||
|
private readonly PowerSupplySettings settings;
|
||||||
|
|
||||||
private DateTime lastStatusLog;
|
private DateTime lastStatusLog;
|
||||||
private ILogger logger;
|
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
private double critical;
|
||||||
|
private double low;
|
||||||
|
|
||||||
public event StatusChangedEventHandler StatusChanged;
|
public event StatusChangedEventHandler StatusChanged;
|
||||||
|
|
||||||
public PowerSupply(ILogger logger)
|
public PowerSupply(ILogger logger, PowerSupplySettings settings)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPowerSupplyStatus GetStatus()
|
public IPowerSupplyStatus GetStatus()
|
||||||
|
@ -37,7 +43,7 @@ namespace SafeExamBrowser.SystemComponents.PowerSupply
|
||||||
var status = new PowerSupplyStatus();
|
var status = new PowerSupplyStatus();
|
||||||
|
|
||||||
status.BatteryCharge = charge;
|
status.BatteryCharge = charge;
|
||||||
status.BatteryChargeStatus = charge <= 0.2 ? (charge <= 0.1 ? BatteryChargeStatus.Critical : BatteryChargeStatus.Low) : BatteryChargeStatus.Okay;
|
status.BatteryChargeStatus = charge <= low ? (charge <= critical ? BatteryChargeStatus.Critical : BatteryChargeStatus.Low) : BatteryChargeStatus.Okay;
|
||||||
status.BatteryTimeRemaining = new TimeSpan(hours, minutes, 0);
|
status.BatteryTimeRemaining = new TimeSpan(hours, minutes, 0);
|
||||||
status.IsOnline = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
|
status.IsOnline = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
|
||||||
|
|
||||||
|
@ -54,12 +60,15 @@ namespace SafeExamBrowser.SystemComponents.PowerSupply
|
||||||
{
|
{
|
||||||
const int TWO_SECONDS = 2000;
|
const int TWO_SECONDS = 2000;
|
||||||
|
|
||||||
|
critical = SanitizeThreshold(settings.ChargeThresholdCritical);
|
||||||
|
low = SanitizeThreshold(settings.ChargeThresholdLow);
|
||||||
|
|
||||||
timer = new Timer(TWO_SECONDS);
|
timer = new Timer(TWO_SECONDS);
|
||||||
timer.Elapsed += Timer_Elapsed;
|
timer.Elapsed += Timer_Elapsed;
|
||||||
timer.AutoReset = true;
|
timer.AutoReset = true;
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
logger.Info("Started monitoring the power supply.");
|
logger.Info($"Started monitoring the power supply (battery charge thresholds: low = {low * 100}%, critical = {critical * 100}%).");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Terminate()
|
public void Terminate()
|
||||||
|
@ -71,6 +80,11 @@ namespace SafeExamBrowser.SystemComponents.PowerSupply
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double SanitizeThreshold(double value)
|
||||||
|
{
|
||||||
|
return value < 0 ? 0 : (value > 1 ? 1 : value);
|
||||||
|
}
|
||||||
|
|
||||||
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
StatusChanged?.Invoke(GetStatus());
|
StatusChanged?.Invoke(GetStatus());
|
||||||
|
|
|
@ -134,6 +134,9 @@ namespace SebWindowsConfig
|
||||||
public const string KeyAudioVolumeLevel = "audioVolumeLevel";
|
public const string KeyAudioVolumeLevel = "audioVolumeLevel";
|
||||||
public const string KeyAudioSetVolumeLevel = "audioSetVolumeLevel";
|
public const string KeyAudioSetVolumeLevel = "audioSetVolumeLevel";
|
||||||
|
|
||||||
|
public const string KeyBatteryChargeThresholdCritical = "batteryChargeThresholdCritical";
|
||||||
|
public const string KeyBatteryChargeThresholdLow = "batteryChargeThresholdLow";
|
||||||
|
|
||||||
//Touch optimized settings
|
//Touch optimized settings
|
||||||
public const String KeyBrowserScreenKeyboard = "browserScreenKeyboard";
|
public const String KeyBrowserScreenKeyboard = "browserScreenKeyboard";
|
||||||
|
|
||||||
|
@ -655,6 +658,8 @@ namespace SebWindowsConfig
|
||||||
SEBSettings.settingsDefault.Add(SEBSettings.KeyAudioVolumeLevel, 25);
|
SEBSettings.settingsDefault.Add(SEBSettings.KeyAudioVolumeLevel, 25);
|
||||||
SEBSettings.settingsDefault.Add(SEBSettings.KeyAudioSetVolumeLevel, false);
|
SEBSettings.settingsDefault.Add(SEBSettings.KeyAudioSetVolumeLevel, false);
|
||||||
SEBSettings.settingsDefault.Add(SEBSettings.KeyAllowDeveloperConsole, false);
|
SEBSettings.settingsDefault.Add(SEBSettings.KeyAllowDeveloperConsole, false);
|
||||||
|
SEBSettings.settingsDefault.Add(SEBSettings.KeyBatteryChargeThresholdCritical, 0.1);
|
||||||
|
SEBSettings.settingsDefault.Add(SEBSettings.KeyBatteryChargeThresholdLow, 0.2);
|
||||||
|
|
||||||
//Touch Settings
|
//Touch Settings
|
||||||
SEBSettings.settingsDefault.Add(SEBSettings.KeyBrowserScreenKeyboard, false);
|
SEBSettings.settingsDefault.Add(SEBSettings.KeyBrowserScreenKeyboard, false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue