Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acquire WakeLock when hosting Swissbit SCUs #86

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using fiskaltrust.AndroidLauncher.Common.Services.SCU;
using fiskaltrust.AndroidLauncher.Common.Signing;
using fiskaltrust.ifPOS.v1;
using fiskaltrust.ifPOS.v1.de;
using fiskaltrust.ifPOS.v1.it;
using fiskaltrust.Middleware.Abstractions;
using fiskaltrust.storage.serialization.V0;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -39,6 +37,7 @@ internal class MiddlewareLauncher
private readonly Dictionary<string, object> _scuParams;
private readonly LogLevel _logLevel;

private Android.OS.PowerManager.WakeLock _wakeLock;
private List<IHelper> _helpers;
private List<IPOS> _poss;
private AbstractScuList _scus;
Expand Down Expand Up @@ -87,6 +86,9 @@ public async Task StartAsync()
switch (scuConfig.Package)
{
case PACKAGE_NAME_DE_SWISSBIT:
// On some (payment) devices, the CPU is turned off as soon as the device becomes remotely idle (i.e. right after processing a receipt) - this seems to also stop the internal clock of the Swissbit TSE.
// To prevent this, we acquire a partial wake lock to keep the CPU running. As this is only required with hardware TSEs, we only acquire the wake lock for the Swissbit SCU for now.
AcquireCpuWakeLock();
await InitializeDESwissbitScuAsync(scuConfig);
break;
case PACKAGE_NAME_DE_FISKALY_CERTIFIED:
Expand Down Expand Up @@ -130,6 +132,8 @@ public async Task StopAsync()
helper.StopEnd();
}

_wakeLock?.Release();

IsRunning = false;
}

Expand Down Expand Up @@ -194,5 +198,12 @@ private static string GetPrimaryUriForSignaturCreationUnit(PackageConfiguration
var grpcUrl = scuConfiguration.Url.FirstOrDefault(x => x.StartsWith("grpc://", StringComparison.InvariantCulture));
return new Uri(grpcUrl ?? scuConfiguration.Url.First()).ToString();
}

private void AcquireCpuWakeLock()
{
var pm = (Android.OS.PowerManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.PowerService);
_wakeLock = pm.NewWakeLock(Android.OS.WakeLockFlags.Partial, "fiskaltrust.AndroidLauncher::KeepAliveWakeLock");
_wakeLock.Acquire();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
<Version>1.3.59</Version>
</PackageReference>
<PackageReference Include="fiskaltrust.Middleware.SCU.DE.Swissbit">
<Version>1.3.48</Version>
<Version>1.3.62</Version>
</PackageReference>
<PackageReference Include="fiskaltrust.Middleware.SCU.DE.SwissbitAndroid">
<Version>1.3.48</Version>
<Version>1.3.62</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore">
<Version>2.2.0</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
Loading