From e9db61ddb745bfbe57136ee2e19049f0f0837607 Mon Sep 17 00:00:00 2001 From: David Tavarez <337107+davidtavarez@users.noreply.github.com> Date: Thu, 18 Aug 2022 17:31:08 +0200 Subject: [PATCH] adding resync control button --- .../Classes/NodeControl.cs | 4 +- .../GrinPlusPlus.Android/GrinNodeService.cs | 37 +++++++++++++++---- .../Properties/AndroidManifest.xml | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/GrinPlusPlus/GrinPlusPlus.Android/Classes/NodeControl.cs b/GrinPlusPlus/GrinPlusPlus.Android/Classes/NodeControl.cs index 869b52b..07470bd 100644 --- a/GrinPlusPlus/GrinPlusPlus.Android/Classes/NodeControl.cs +++ b/GrinPlusPlus/GrinPlusPlus.Android/Classes/NodeControl.cs @@ -133,8 +133,10 @@ public static bool IsTorRunning() return GetProcessId(pTor) != -1; } - public static bool DeleteNodeDataFolder(string dataFolder) + public static bool DeleteNodeDataFolder() { + string dataFolder = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), ".GrinPP/MAINNET/NODE"); + try { if (NodeControl.IsNodeRunning()) diff --git a/GrinPlusPlus/GrinPlusPlus.Android/GrinNodeService.cs b/GrinPlusPlus/GrinPlusPlus.Android/GrinNodeService.cs index 30448f6..1b6ed01 100644 --- a/GrinPlusPlus/GrinPlusPlus.Android/GrinNodeService.cs +++ b/GrinPlusPlus/GrinPlusPlus.Android/GrinNodeService.cs @@ -44,11 +44,12 @@ public override StartCommandResult OnStartCommand(Intent intent, StartCommandFla { InitializeNodeService(); - if(NodeControl.IsNodeRunning()) + if (NodeControl.IsNodeRunning()) { RegisterForegroundService("Initializing Node..."); SetNodeTimer(); - } else + } + else { RegisterForegroundService("Not Running"); } @@ -66,10 +67,8 @@ public override StartCommandResult OnStartCommand(Intent intent, StartCommandFla } catch { } - if (intent.Action.Equals(Constants.ACTION_STOP_SERVICE)) + if (intent.Action.Equals(Constants.ACTION_STOP_SERVICE) || intent.Action.Equals(Constants.ACTION_RESYNC_NODE)) { - Log.Info(TAG, "Stop Service called."); - try { if (timer != null) @@ -85,6 +84,11 @@ public override StartCommandResult OnStartCommand(Intent intent, StartCommandFla Log.Verbose(TAG, e.Message); } + if (intent.Action.Equals(Constants.ACTION_RESYNC_NODE)) + { + NodeControl.DeleteNodeDataFolder(); + } + StopForeground(true); StopSelf(); @@ -92,8 +96,6 @@ public override StartCommandResult OnStartCommand(Intent intent, StartCommandFla } else if (intent.Action.Equals(Constants.ACTION_RESTART_NODE)) { - Log.Info(TAG, "Restart Grin Node called."); - InitializeNodeService(); } } @@ -220,6 +222,7 @@ private void RegisterForegroundService(string status) .SetOngoing(true) .AddAction(BuildRestartNodeAction()) .AddAction(BuildStopServiceAction()) + .AddAction(BuildResyncNodeAction()) .Build(); // Enlist this instance of the service as a foreground service @@ -298,6 +301,26 @@ Notification.Action BuildStopServiceAction() var builder = new Notification.Action.Builder(null, "Close", stopServicePendingIntent); + + return builder.Build(); + } + + /// + /// Builds a Notification.Action that will instruct the service to resync the node. + /// + /// The resync node action. + Notification.Action BuildResyncNodeAction() + { + var action = "Resync"; + + var restartIntent = new Intent(this, GetType()); + restartIntent.SetAction(Constants.ACTION_RESYNC_NODE); + var restartTimerPendingIntent = PendingIntent.GetService(this, 0, restartIntent, PendingIntentFlags.Immutable); + + var builder = new Notification.Action.Builder(null, + action, + restartTimerPendingIntent); + return builder.Build(); } } diff --git a/GrinPlusPlus/GrinPlusPlus.Android/Properties/AndroidManifest.xml b/GrinPlusPlus/GrinPlusPlus.Android/Properties/AndroidManifest.xml index 5e247d9..e53f2f1 100644 --- a/GrinPlusPlus/GrinPlusPlus.Android/Properties/AndroidManifest.xml +++ b/GrinPlusPlus/GrinPlusPlus.Android/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - +