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 @@  - +