Skip to content

Commit

Permalink
adding resync control button
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtavarez committed Aug 18, 2022
1 parent 1208aaf commit e9db61d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
4 changes: 3 additions & 1 deletion GrinPlusPlus/GrinPlusPlus.Android/Classes/NodeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
37 changes: 30 additions & 7 deletions GrinPlusPlus/GrinPlusPlus.Android/GrinNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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)
Expand All @@ -85,15 +84,18 @@ 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();

System.Diagnostics.Process.GetCurrentProcess().Kill();
}
else if (intent.Action.Equals(Constants.ACTION_RESTART_NODE))
{
Log.Info(TAG, "Restart Grin Node called.");

InitializeNodeService();
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -298,6 +301,26 @@ Notification.Action BuildStopServiceAction()
var builder = new Notification.Action.Builder(null,
"Close",
stopServicePendingIntent);

return builder.Build();
}

/// <summary>
/// Builds a Notification.Action that will instruct the service to resync the node.
/// </summary>
/// <returns>The resync node action.</returns>
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="7" android:versionName="0.3.4" android:installLocation="internalOnly" package="com.grinplusplus.mobile">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="7" android:versionName="0.3.5" android:installLocation="internalOnly" package="com.grinplusplus.mobile">
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
Expand Down

0 comments on commit e9db61d

Please sign in to comment.