-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geolocation: Add #nullable for Essentials Geolocation code #13371
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
120ce41
enabled nullable checks for GeolocationRequest class
vividos e38f534
enabled nullable checks for more Geolocation source files
vividos 70a8e18
enabled nullable checks for Geolocation Android and iOS implementation
vividos 877c808
changed null checks as suggested in review
vividos 2bc9e6d
fixed nullable errors for Tizen
vividos cdf8702
Fix some forgotte == null
mandel-macaque c6387da
Fix some forgotte != null
mandel-macaque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#nullable enable | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
|
@@ -10,14 +11,14 @@ namespace Microsoft.Maui.Devices.Sensors | |
{ | ||
partial class GeolocationImplementation : IGeolocation | ||
{ | ||
CLLocationManager listeningManager; | ||
CLLocationManager? listeningManager; | ||
|
||
/// <summary> | ||
/// Indicates if currently listening to location updates while the app is in foreground. | ||
/// </summary> | ||
public bool IsListeningForeground { get => listeningManager != null; } | ||
|
||
public async Task<Location> GetLastKnownLocationAsync() | ||
public async Task<Location?> GetLastKnownLocationAsync() | ||
{ | ||
if (!CLLocationManager.LocationServicesEnabled) | ||
throw new FeatureNotEnabledException("Location services are not enabled on device."); | ||
|
@@ -37,7 +38,7 @@ public async Task<Location> GetLastKnownLocationAsync() | |
return location?.ToLocation(reducedAccuracy); | ||
} | ||
|
||
public async Task<Location> GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) | ||
public async Task<Location?> GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) | ||
{ | ||
ArgumentNullException.ThrowIfNull(request); | ||
|
||
|
@@ -50,7 +51,7 @@ public async Task<Location> GetLocationAsync(GeolocationRequest request, Cancell | |
// so just use the main loop | ||
var manager = MainThread.InvokeOnMainThread(() => new CLLocationManager()); | ||
|
||
var tcs = new TaskCompletionSource<CLLocation>(manager); | ||
var tcs = new TaskCompletionSource<CLLocation?>(manager); | ||
|
||
var listener = new SingleLocationListener(); | ||
listener.LocationHandler += HandleLocation; | ||
|
@@ -155,7 +156,7 @@ public async Task<bool> StartListeningForegroundAsync(GeolocationListeningReques | |
|
||
void HandleLocation(CLLocation clLocation) | ||
{ | ||
OnLocationChanged(clLocation?.ToLocation(reducedAccuracy)); | ||
OnLocationChanged(clLocation.ToLocation(reducedAccuracy)); | ||
} | ||
|
||
void HandleError(GeolocationError error) | ||
|
@@ -172,7 +173,8 @@ void HandleError(GeolocationError error) | |
/// </summary> | ||
public void StopListeningForeground() | ||
{ | ||
if (!IsListeningForeground) | ||
if (!IsListeningForeground || | ||
listeningManager is null) | ||
return; | ||
|
||
listeningManager.StopUpdatingLocation(); | ||
|
@@ -183,7 +185,7 @@ public void StopListeningForeground() | |
listener.ErrorHandler = null; | ||
} | ||
|
||
listeningManager.Delegate = null; | ||
listeningManager.WeakDelegate = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure setting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jfversluis the third... |
||
|
||
listeningManager = null; | ||
} | ||
|
@@ -193,7 +195,7 @@ class SingleLocationListener : CLLocationManagerDelegate | |
{ | ||
bool wasRaised = false; | ||
|
||
internal Action<CLLocation> LocationHandler { get; set; } | ||
internal Action<CLLocation>? LocationHandler { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations) | ||
|
@@ -217,9 +219,9 @@ public override void LocationsUpdated(CLLocationManager manager, CLLocation[] lo | |
|
||
class ContinuousLocationListener : CLLocationManagerDelegate | ||
{ | ||
internal Action<CLLocation> LocationHandler { get; set; } | ||
internal Action<CLLocation>? LocationHandler { get; set; } | ||
|
||
internal Action<GeolocationError> ErrorHandler { get; set; } | ||
internal Action<GeolocationError>? ErrorHandler { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/Essentials/src/Geolocation/GeolocationAccuracyExtensionMethods.uwp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#nullable enable | ||
using System; | ||
|
||
namespace Microsoft.Maui.Devices.Sensors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#nullable enable | ||
|
||
namespace Microsoft.Maui.Devices.Sensors | ||
{ | ||
public partial class GeolocationRequest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if LocationManager can ever be null on a sane Android environment, but there might be some weird custom ROMs; I guess the best is to throw
FeatureNotSupportedException
then...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfversluis there are still my three questions...