Skip to content

Remove current location retrieval from upload process entirely #1644

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

Merged

Conversation

misaochan
Copy link
Member

Temporary fix for #1599 . We are concerned that people who enabled the "automatically get current location" setting prior to the subtext change may not realize that their location is being added to the image's location template. This removes current location retrieval entirely from the upload process, and removes the Setting as well.

Where possible, I have left methods intact so that in the future if we decide to reimplement this (retrieving current location solely for category suggestions but not adding it to the template), we will not need to rewrite code. However, I have removed most of the method calls, and methods that would affect the user (e.g. the snackbar requesting location permissions).

As an added bonus, this should fix #1515 since the LocationListener will not be registered in ShareActivity.

Tested on Nexus S emulator running API 25 on betaDebug. To test:

  • Make sure GPS is on and your image has no geotagged coordinates
  • Upload that image
  • Check your uploaded image and make sure no location template was added to it

@codecov-io
Copy link

codecov-io commented Jun 19, 2018

Codecov Report

Merging #1644 into 2.8-release will increase coverage by 0.03%.
The diff coverage is 0%.

Impacted file tree graph

@@              Coverage Diff               @@
##           2.8-release   #1644      +/-   ##
==============================================
+ Coverage         3.87%    3.9%   +0.03%     
==============================================
  Files              150     150              
  Lines             7571    7501      -70     
  Branches           710     703       -7     
==============================================
  Hits               293     293              
+ Misses            7261    7191      -70     
  Partials            17      17
Impacted Files Coverage Δ
...java/fr/free/nrw/commons/upload/ShareActivity.java 0% <ø> (ø) ⬆️
...java/fr/free/nrw/commons/upload/FileProcessor.java 0% <0%> (ø) ⬆️
.../java/fr/free/nrw/commons/upload/GPSExtractor.java 0% <0%> (ø) ⬆️
...free/nrw/commons/upload/MultipleShareActivity.java 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18b0517...b5161d6. Read the comment docs.

@whym
Copy link
Collaborator

whym commented Jun 20, 2018

Tested on real device (API 24) and it worked fine. An upload with no EXIF location info has no location template and an upload with EXIF location ifo has one.

android:title="@string/preference_category_location">

<SwitchPreference
android:key="allowGps"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of the idea of leaving some trace of the key string "allowGps" so that future developers will not accidentally reuse it? (e.g. "// key 'allowGps' was used before - do not reuse it unless you revive the same feature.")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good plan, but where should we mention this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could do that in preferences.xml in place of the removed code. Or maybe somewhere in the wiki pages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me - added a comment there. :) Are we all good to merge?

Copy link
Collaborator

@whym whym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I made a suggestion but it doesn't mean I'm disapproving this even if the suggestion is not applied.)

@sivaraam
Copy link
Member

sivaraam commented Jun 21, 2018

Where possible, I have left methods intact so that in the future if we decide to reimplement this (retrieving current location solely for category suggestions but not adding it to the template), we will not need to rewrite code

IMHO, it's better to remove functions that aren't used in the app as it would confuse the person who would be reading the related code in the future. Not many would expect dead code to be held back intentionally. It might also improve code hygiene. You could always get them back with a git revert when you do decide to re-use them rather than rewriting it (rewriting might be a better alternative if the code is very old).

Just for the sake of an example and nothing more, the Wikipedia app recently had a feature called "Offline library" which was actively developed until a month back or so. Since they discovered potential blockers for the feature they're shelving the feature for now. For that removed the relevant code completely rather than keeping it back.

@nicolas-raoul
Copy link
Member

I also generally believe that unused code should be removed, to make the code smaller.

@misaochan
Copy link
Member Author

Thanks for the feedback guys. Will do that soon. :)

@misaochan
Copy link
Member Author

Removed unused code. :)

@neslihanturan
Copy link
Collaborator

@misaochan I have tested and get this error on beggining of app:

FATAL EXCEPTION: main Process: fr.free.nrw.commons.debug, PID: 8641 java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.free.nrw.commons.debug/fr.free.nrw.commons.contributions.ContributionsActivity}: android.database.sqlite.SQLiteException: Can't downgrade database from version 7 to 6 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from version 7 to 6 at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:360) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:254) at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187) at fr.free.nrw.commons.contributions.ContributionsContentProvider.query(ContributionsContentProvider.java:52) at android.content.ContentProvider.query(ContentProvider.java:1017) at android.content.ContentProvider$Transport.query(ContentProvider.java:238) at android.content.ContentProviderClient.query(ContentProviderClient.java:136) at android.content.ContentProviderClient.query(ContentProviderClient.java:118) at fr.free.nrw.commons.contributions.ContributionDao.loadAllContributions(ContributionDao.java:50) at fr.free.nrw.commons.contributions.ContributionsActivity.onAuthCookieAcquired(ContributionsActivity.java:116) at fr.free.nrw.commons.auth.AuthenticatedActivity.requestAuthToken(AuthenticatedActivity.java:26) at fr.free.nrw.commons.contributions.ContributionsActivity.onCreate(ContributionsActivity.java:140) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  06-28 19:35:25.542 1645-1973/system_process W/ActivityManager: Force finishing activity fr.free.nrw.commons.debug/fr.free.nrw.commons.contributions.ContributionsActivity

@neslihanturan
Copy link
Collaborator

Re-installing the app solves the crash.

@misaochan
Copy link
Member Author

Hmm. It is still a legit error, but doesn't appear to be related to this PR - I haven't modified any code in the Contributions package at all. Should we create a new issue for it? Might be a bit difficult to reproduce though, haha.

@neslihanturan
Copy link
Collaborator

neslihanturan commented Jun 28, 2018

If you have an old installation on an emulator, can you try to pull your changes there and test? I think the error will be appeared then.

I didn't experienced this error on other branches.

@misaochan
Copy link
Member Author

misaochan commented Jun 30, 2018

@neslihanturan I did as you described and could not reproduce the error. I do think it's very unlikely to be caused by this PR as none of the classes in the stack trace were modified. I would suggest merging if it otherwise works for you, and if the issue reoccurs when we test the branch, we can fix it. Either way, I don't think the fix should be in this PR, but rather a separate one.

Edit: It seems according to https://stackoverflow.com/questions/24053786/cant-downgrade-database-from-version-2-to-1-even-after-fresh-install-and-re-run that the cause could be code on the previous version of the app erroneously incrementing the DB version. So that explains why I wasn't able to reproduce it, since I would likely have used a different "old installation" from yours. Which branch were you testing prior to this one, do you remember?

@whym
Copy link
Collaborator

whym commented Jul 6, 2018

It appears that the DB version was changed in the 'browse' branch from 6 to 7: ae09445#diff-1c0d8106634cdf0a1f9d0087c46c3e9d So I think we are safe to ignore it in this particular PR.

The DB downgrade issue is tracked in #1589.

@whym
Copy link
Collaborator

whym commented Jul 6, 2018

I tested it again with a betaRelease build and it still worked fine for me. :)

@misaochan
Copy link
Member Author

Thanks for testing again, @whym . :) Would anyone like to go ahead and merge?

android:summary="@string/allow_gps_summary" />

</PreferenceCategory>
<!-- The key 'allowGps' was used before and has since been removed based on the discussion at #1599.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that you added this comment here. :)

@maskaravivek maskaravivek merged commit 2d831c0 into commons-app:2.8-release Jul 7, 2018
@misaochan misaochan deleted the fix-automatic-location branch July 8, 2018 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants