From 03a151fc7dd9415569b4da0e11ab2d0d049b8fb1 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 24 Oct 2024 12:36:50 +0100 Subject: [PATCH 1/5] fix: only request permissions to the gallery for Android <= 9 (API 28) Context: For Android >= 10, we don't need to request permissions to save the photo to the gallery. More info here: https://developer.android.com/media/camera/camera-deprecated/photobasics#TaskPath References: https://outsystemsrd.atlassian.net/browse/RMET-3767 --- .../capacitorjs/plugins/camera/CameraPlugin.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java b/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java index 2dce20da1..bdd1315b2 100644 --- a/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java +++ b/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java @@ -204,7 +204,18 @@ private boolean checkCameraPermissions(PluginCall call) { boolean hasGalleryPerms = getPermissionState(SAVE_GALLERY) == PermissionState.GRANTED; // If we want to save to the gallery, we need two permissions - if (settings.isSaveToGallery() && !(hasCameraPerms && hasGalleryPerms) && isFirstRequest) { + // actually we only need permissions to save to gallery for Android <= 9 (API 28) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + // we might still need to request permission for the camera + if (!hasCameraPerms) { + requestPermissionForAlias(CAMERA, call, "cameraPermissionsCallback"); + return false; + } + return true; + } + + // we need to request permissions to save to gallery for Android <= 9 + else if (settings.isSaveToGallery() && !(hasCameraPerms && hasGalleryPerms) && isFirstRequest) { isFirstRequest = false; String[] aliases; if (needCameraPerms) { From 65c526a93e74f33a0eaa592dba0c1b7df8b0f5e4 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 24 Oct 2024 12:37:15 +0100 Subject: [PATCH 2/5] Revert "fix: only request permissions to the gallery for Android <= 9 (API 28)" This reverts commit 03a151fc7dd9415569b4da0e11ab2d0d049b8fb1. --- .../capacitorjs/plugins/camera/CameraPlugin.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java b/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java index bdd1315b2..2dce20da1 100644 --- a/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java +++ b/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java @@ -204,18 +204,7 @@ private boolean checkCameraPermissions(PluginCall call) { boolean hasGalleryPerms = getPermissionState(SAVE_GALLERY) == PermissionState.GRANTED; // If we want to save to the gallery, we need two permissions - // actually we only need permissions to save to gallery for Android <= 9 (API 28) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - // we might still need to request permission for the camera - if (!hasCameraPerms) { - requestPermissionForAlias(CAMERA, call, "cameraPermissionsCallback"); - return false; - } - return true; - } - - // we need to request permissions to save to gallery for Android <= 9 - else if (settings.isSaveToGallery() && !(hasCameraPerms && hasGalleryPerms) && isFirstRequest) { + if (settings.isSaveToGallery() && !(hasCameraPerms && hasGalleryPerms) && isFirstRequest) { isFirstRequest = false; String[] aliases; if (needCameraPerms) { From 246a9b766c48e94714fce409f5a36e8ffe9dd1cf Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 5 Dec 2024 09:36:45 +0000 Subject: [PATCH 3/5] feat: add minimumUpdateInterval parameter to startWatch Context: We were hardcoding the minimum update interval for location updates to 5 seconds, which meant that if there was an update available in less than 5 seconds, that update would only be delivered after 5 seconds. Instead, this value should be set by the user/developer, so they can better control the frequency of location updates. References: https://outsystemsrd.atlassian.net/browse/RMET-3338 --- geolocation/README.md | 11 ++++++----- .../capacitorjs/plugins/geolocation/Geolocation.java | 4 ++-- .../plugins/geolocation/GeolocationPlugin.java | 2 ++ geolocation/src/definitions.ts | 11 +++++++++++ geolocation/src/web.ts | 1 + 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/geolocation/README.md b/geolocation/README.md index 2c2f86313..1b9b72259 100644 --- a/geolocation/README.md +++ b/geolocation/README.md @@ -171,11 +171,12 @@ Request location permissions. Will throw if system location services are disabl #### PositionOptions -| Prop | Type | Description | Default | Since | -| ------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | -| **`enableHighAccuracy`** | boolean | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | false | 1.0.0 | -| **`timeout`** | number | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | 10000 | 1.0.0 | -| **`maximumAge`** | number | The maximum age in milliseconds of a possible cached position that is acceptable to return | 0 | 1.0.0 | +| Prop | Type | Description | Default | Since | +| --------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | +| **`enableHighAccuracy`** | boolean | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | false | 1.0.0 | +| **`timeout`** | number | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | 10000 | 1.0.0 | +| **`maximumAge`** | number | The maximum age in milliseconds of a possible cached position that is acceptable to return | 0 | 1.0.0 | +| **`minimumUpdateInterval`** | number | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. | 5000 | 6.1.0 | #### ClearWatchOptions diff --git a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java index 41b8af269..07f9b7496 100644 --- a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java +++ b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java @@ -68,7 +68,7 @@ public void sendLocation(boolean enableHighAccuracy, final LocationResultCallbac } @SuppressWarnings("MissingPermission") - public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, final LocationResultCallback resultCallback) { + public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, int minUpdateInterval, final LocationResultCallback resultCallback) { int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context); if (resultCode == ConnectionResult.SUCCESS) { clearLocationUpdates(); @@ -87,7 +87,7 @@ public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, fina LocationRequest locationRequest = new LocationRequest.Builder(10000) .setMaxUpdateDelayMillis(timeout) - .setMinUpdateIntervalMillis(5000) + .setMinUpdateIntervalMillis(minUpdateInterval) .setPriority(priority) .build(); diff --git a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java index 84514a682..d198c675b 100644 --- a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java +++ b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java @@ -172,10 +172,12 @@ public void error(String message) { @SuppressWarnings("MissingPermission") private void startWatch(final PluginCall call) { int timeout = call.getInt("timeout", 10000); + int minUpdateInterval = call.getInt("minimumUpdateInterval", 5000); implementation.requestLocationUpdates( isHighAccuracy(call), timeout, + minUpdateInterval, new LocationResultCallback() { @Override public void success(Location location) { diff --git a/geolocation/src/definitions.ts b/geolocation/src/definitions.ts index 94fd9b61f..3659faac9 100644 --- a/geolocation/src/definitions.ts +++ b/geolocation/src/definitions.ts @@ -180,6 +180,17 @@ export interface PositionOptions { * @since 1.0.0 */ maximumAge?: number; + + /** + * The minumum update interval for location updates. + * + * If location updates are available faster than this interval then an update + * will only occur if the minimum update interval has expired since the last location update. + * + * @default 5000 + * @since 6.1.0 + */ + minimumUpdateInterval?: number; } export type WatchPositionCallback = ( diff --git a/geolocation/src/web.ts b/geolocation/src/web.ts index 6830085de..5288ff9c0 100644 --- a/geolocation/src/web.ts +++ b/geolocation/src/web.ts @@ -44,6 +44,7 @@ export class GeolocationWeb extends WebPlugin implements GeolocationPlugin { enableHighAccuracy: false, timeout: 10000, maximumAge: 0, + minimumUpdateInterval: 5000, ...options, }, ); From a938d3f39e2d70daece688fd3dcd1dedc198ed4b Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 6 Dec 2024 17:23:14 +0000 Subject: [PATCH 4/5] refactor: add note to new parameter's documentation References: https://outsystemsrd.atlassian.net/browse/RMET-3338 --- .../capacitorjs/plugins/geolocation/Geolocation.java | 7 ++++++- geolocation/src/definitions.ts | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java index 07f9b7496..e5263a0a2 100644 --- a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java +++ b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java @@ -68,7 +68,12 @@ public void sendLocation(boolean enableHighAccuracy, final LocationResultCallbac } @SuppressWarnings("MissingPermission") - public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, int minUpdateInterval, final LocationResultCallback resultCallback) { + public void requestLocationUpdates( + boolean enableHighAccuracy, + int timeout, + int minUpdateInterval, + final LocationResultCallback resultCallback + ) { int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context); if (resultCode == ConnectionResult.SUCCESS) { clearLocationUpdates(); diff --git a/geolocation/src/definitions.ts b/geolocation/src/definitions.ts index 3659faac9..9e6239e1d 100644 --- a/geolocation/src/definitions.ts +++ b/geolocation/src/definitions.ts @@ -181,16 +181,18 @@ export interface PositionOptions { */ maximumAge?: number; - /** + /** * The minumum update interval for location updates. - * - * If location updates are available faster than this interval then an update + * + * If location updates are available faster than this interval then an update * will only occur if the minimum update interval has expired since the last location update. - * + * + * This parameter is only available for Android. It has no effect on iOS or Web platforms. + * * @default 5000 * @since 6.1.0 */ - minimumUpdateInterval?: number; + minimumUpdateInterval?: number; } export type WatchPositionCallback = ( From 07f9f9820f77401490dcd7781436c98103988836 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 6 Dec 2024 17:39:22 +0000 Subject: [PATCH 5/5] chore: update README References: https://outsystemsrd.atlassian.net/browse/RMET-3338 --- geolocation/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/geolocation/README.md b/geolocation/README.md index 1614f8347..106e4a0ea 100644 --- a/geolocation/README.md +++ b/geolocation/README.md @@ -171,12 +171,12 @@ Request location permissions. Will throw if system location services are disabl #### PositionOptions -| Prop | Type | Description | Default | Since | -| --------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | -| **`enableHighAccuracy`** | boolean | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | false | 1.0.0 | -| **`timeout`** | number | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | 10000 | 1.0.0 | -| **`maximumAge`** | number | The maximum age in milliseconds of a possible cached position that is acceptable to return | 0 | 1.0.0 | -| **`minimumUpdateInterval`** | number | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. | 5000 | 6.1.0 | +| Prop | Type | Description | Default | Since | +| --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | +| **`enableHighAccuracy`** | boolean | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | false | 1.0.0 | +| **`timeout`** | number | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | 10000 | 1.0.0 | +| **`maximumAge`** | number | The maximum age in milliseconds of a possible cached position that is acceptable to return | 0 | 1.0.0 | +| **`minimumUpdateInterval`** | number | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | 5000 | 6.1.0 | #### ClearWatchOptions