Skip to content

Commit

Permalink
Additional aggressive restart options for Android transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Oct 17, 2023
1 parent 25ffce5 commit 9ddaecd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion samples/Sample.Api/Sample.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.12" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
9 changes: 6 additions & 3 deletions samples/Sample.Maui/Sample.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<ApplicationTitle>Shiny</ApplicationTitle>
<ApplicationId>org.shiny.samples</ApplicationId>
<ApplicationIdGuid>3E54A75D-D399-4272-8326-54510C872263</ApplicationIdGuid>
Expand All @@ -32,6 +32,9 @@
-->
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
Expand All @@ -46,11 +49,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="ReactiveUI.Fody" Version="19.4.1" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.1" />
<PackageReference Include="Prism.DryIoc.Maui" Version="8.1.273-pre" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="3.2.0" />
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 13 additions & 7 deletions src/Shiny.Net.Http/Platforms/Android/HttpTransferProcess.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reactive.Disposables;
Expand Down Expand Up @@ -53,10 +54,12 @@ public void Run(Action onComplete)

this.connectivity
.WhenInternetStatusChanged()
.Where(x => x == true)
.DistinctUntilChanged()
.SubscribeAsync(async _ =>
{
if (!this.connectivity.IsInternetAvailable())
return;

var fullInternet = this.connectivity.Access == NetworkAccess.Internet;

// this will start with an event triggering everything
Expand Down Expand Up @@ -210,10 +213,13 @@ await this.delegates

this.repository.Remove(transfer);
}

catch (Java.Net.SocketException)
catch (IOException ex) when (ex.InnerException is Java.Net.SocketException)
{
this.PauseTransfer(transfer, "Android Network Disconnected", ex);
}
catch (Java.Net.SocketException ex)
{
this.PauseTransfer(transfer, "Android Network Disconnected");
this.PauseTransfer(transfer, "Android Network Disconnected", ex);
}
catch (OperationCanceledException)
{
Expand All @@ -222,14 +228,14 @@ await this.delegates
catch (Exception ex)
{
// should always retry unless server fails
this.PauseTransfer(transfer, "Error with transfer - " + ex.ToString());
this.PauseTransfer(transfer, "Error with transfer - " + ex.ToString(), ex);
}
}


void PauseTransfer(HttpTransfer transfer, string reason)
void PauseTransfer(HttpTransfer transfer, string reason, Exception exception)
{
this.logger.StandardInfo(transfer.Identifier, reason);
this.logger.StandardInfo(transfer.Identifier, reason + $" - {exception}");
this.repository.Set(transfer with
{
Status = HttpTransferState.PausedByNoNetwork
Expand Down
45 changes: 24 additions & 21 deletions tests/Shiny.Tests/HttpTransferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Shiny.Tests;

public class HttpTransferTests : AbstractShinyTests
{
// TODO: test multiple uploads while monitoring
// TODO: mock disconnects

// point at our test api
public HttpTransferTests(ITestOutputHelper output) : base(output) { }

Expand Down Expand Up @@ -267,27 +270,27 @@ await manager.Queue(new HttpTransferRequest(

#if ANDROID
// Test connectivity flops by injecting mock connectivity
[Fact(DisplayName = "HTTP Transfers (Android) - Connectivity Test")]
public async Task AndroidConnectivityTest()
{
var conn = this.GetService<MockConnectivity>();
conn.Change(NetworkAccess.None);

var manager = this.GetService<IHttpTransferManager>();
var id = Guid.NewGuid().ToString();

//await manager.Queue(new HttpTransferRequest(
// id,
// this.GetUri(isUpload, false),
// isUpload,
// this.GetLocalPath(isUpload),
// Headers: new Dictionary<string, string>
// {
// { "Test", "Test" }
// }
//));
// TODO: ensure fg service stays on
}
//[Fact(DisplayName = "HTTP Transfers (Android) - Connectivity Test")]
//public async Task AndroidConnectivityTest()
//{
// var conn = this.GetService<MockConnectivity>();
// conn.Change(NetworkAccess.None);

// var manager = this.GetService<IHttpTransferManager>();
// var id = Guid.NewGuid().ToString();

// //await manager.Queue(new HttpTransferRequest(
// // id,
// // this.GetUri(isUpload, false),
// // isUpload,
// // this.GetLocalPath(isUpload),
// // Headers: new Dictionary<string, string>
// // {
// // { "Test", "Test" }
// // }
// //));
// // TODO: ensure fg service stays on
//}
#endif

string GetUri(bool upload, bool includeBody)
Expand Down

0 comments on commit 9ddaecd

Please sign in to comment.