Skip to content

Commit

Permalink
Merge pull request #86 from fiskaltrust/user/tsc/wake-lock
Browse files Browse the repository at this point in the history
Acquire WakeLock when hosting Swissbit SCUs
  • Loading branch information
TSchmiedlechner authored Sep 5, 2024
2 parents 5ffae2d + 48b4def commit 8d42b84
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
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>

0 comments on commit 8d42b84

Please sign in to comment.