-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
5196: Fix in-app camera location loss #5249
Merged
nicolas-raoul
merged 20 commits into
commons-app:master
from
RitikaPahwa4444:in_app_camera_location_loss
Sep 1, 2023
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
02acabe
fix in-app camera location loss
RitikaPahwa4444 d6ac060
fix failing unit tests
RitikaPahwa4444 655ff4c
UploadMediaDetailFragmentUnitTest: modify testOnActivityResultAddLoca…
RitikaPahwa4444 a8e0c54
reintroduce removed variable
RitikaPahwa4444 7208018
enable prePopulateCategoriesAndDepictionsBy for current user location
RitikaPahwa4444 3c0339b
add relevant comment and fix failing test
RitikaPahwa4444 5f9ff36
modify dialog and disable location tag redaction from EXIF
RitikaPahwa4444 e72be00
modify in-app camera dialog flow and change location to inAppPictureL…
RitikaPahwa4444 74f8c13
change location to inAppPictureLocation
RitikaPahwa4444 fa8674c
fix location flow
RitikaPahwa4444 def8079
Merge branch 'master' into in_app_camera_location_loss
RitikaPahwa4444 5f873d1
preferences.xml: remove redundant default value
RitikaPahwa4444 f0dd7d2
inform users about location loss happening for first upload
RitikaPahwa4444 5837b8b
Merge branch 'commons-app:master' into in_app_camera_location_loss
RitikaPahwa4444 a8783f6
FileProcessor.kt: remove commented-out code
RitikaPahwa4444 96c7b4d
prevent user location from getting attached to images with no EXIF lo…
RitikaPahwa4444 4417140
handle onPermissionDenied for location permission
RitikaPahwa4444 28618ce
remove last location when the user turns the GPS off
RitikaPahwa4444 efbd199
disable photo picker and in app camera preferences in settings for lo…
RitikaPahwa4444 0a2a10b
remove debug statements and add toast inside runnables
RitikaPahwa4444 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
98 changes: 98 additions & 0 deletions
98
app/src/main/java/fr/free/nrw/commons/location/LocationPermissionsHelper.java
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package fr.free.nrw.commons.location; | ||
|
||
import android.Manifest.permission; | ||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.provider.Settings; | ||
import fr.free.nrw.commons.R; | ||
import fr.free.nrw.commons.utils.DialogUtil; | ||
import fr.free.nrw.commons.utils.PermissionUtils; | ||
|
||
/** | ||
* Helper class to handle location permissions | ||
*/ | ||
public class LocationPermissionsHelper { | ||
Activity activity; | ||
LocationServiceManager locationManager; | ||
public LocationPermissionsHelper(Activity activity, LocationServiceManager locationManager) { | ||
this.activity = activity; | ||
this.locationManager = locationManager; | ||
} | ||
public static class Dialog { | ||
int dialogTitleResource; | ||
int dialogTextResource; | ||
|
||
public Dialog(int dialogTitle, int dialogText) { | ||
dialogTitleResource = dialogTitle; | ||
dialogTextResource = dialogText; | ||
} | ||
} | ||
|
||
public void handleLocationPermissions(Dialog locationAccessDialog, | ||
Dialog locationOffDialog) { | ||
requestForLocationAccess(locationAccessDialog, locationOffDialog); | ||
} | ||
|
||
/** | ||
* Ask for location permission if the user agrees on attaching location with pictures | ||
* and the app does not have the access to location | ||
* | ||
* @param locationAccessDialog | ||
* @param locationOffDialog | ||
*/ | ||
private void requestForLocationAccess( | ||
Dialog locationAccessDialog, | ||
Dialog locationOffDialog | ||
) { | ||
PermissionUtils.checkPermissionsAndPerformAction(activity, | ||
permission.ACCESS_FINE_LOCATION, | ||
() -> { | ||
if(!isLocationAccessToAppsTurnedOn()) { | ||
showLocationOffDialog(locationOffDialog); | ||
} | ||
}, | ||
() -> {}, | ||
locationAccessDialog.dialogTitleResource, | ||
locationAccessDialog.dialogTextResource); | ||
} | ||
|
||
/** | ||
* Check if apps have access to location even after having individual access | ||
* | ||
* @return | ||
*/ | ||
private boolean isLocationAccessToAppsTurnedOn() { | ||
return (locationManager.isNetworkProviderEnabled() || locationManager.isGPSProviderEnabled()); | ||
} | ||
|
||
/** | ||
* Ask user to grant location access to apps | ||
* | ||
*/ | ||
|
||
private void showLocationOffDialog(Dialog locationOffDialog) { | ||
DialogUtil | ||
.showAlertDialog(activity, | ||
activity.getString(locationOffDialog.dialogTitleResource), | ||
activity.getString(locationOffDialog.dialogTextResource), | ||
activity.getString(R.string.title_app_shortcut_setting), | ||
() -> openLocationSettings(), | ||
true); | ||
} | ||
|
||
/** | ||
* Open location source settings so that apps with location access can access it | ||
* | ||
* TODO: modify it to fix https://github.com/commons-app/apps-android-commons/issues/5255 | ||
*/ | ||
|
||
private void openLocationSettings() { | ||
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | ||
final PackageManager packageManager = activity.getPackageManager(); | ||
|
||
if (intent.resolveActivity(packageManager)!= null) { | ||
activity.startActivity(intent); | ||
} | ||
} | ||
} |
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.
We're presuming the device location would be turned on whenever the setting is turned on. This is incorrect since the user has the freedom to turn on location of their device even after the setting is turned on.
Ditto on the location permission.
It is prudent to verify that location permission is available and location is turned on whenever the setting is
true
.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.
We've already prompted the user to turn it on, redirected to the Settings too.
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.
The world is never ideal when it comes to Android. The user can have the setting enabled and then later on turn off location on their device. This is a normal case which we should be wary of. That's precisely why the Nearby feature asks user to turn on location when it is turned off.
The same applies for the location permission (especially on Android 11 and above where permissions are auto-removed for unused apps). So, it is the ideal case to ensure we have location permission and if its unavailable request for the same.
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.
A user who wants pictures to be geo-tagged will be turning location on for the camera too but I see it was a bad assumption. Thank you for explaining it! :)