Skip to content

Commit

Permalink
Fix one more shared preferences crash.
Browse files Browse the repository at this point in the history
2.6.7-p2 introduced a bad bug in which it mixed up an int and a string
used as error indications for bad downloads. As a result, most poeple
crashed on launch. 2.6.7-p3 was pushed and fixed this for 99% of people.
However, there is still a small set of people (84 people at the time of
this writing) who didn't crash at the bad logic in 2.6.7-p2, and thus
stored the error data in the wrong format. When 2.6.7-p3 fixed it, those
people started having crashes as well.

This should (insha'Allah) fix this issue.
  • Loading branch information
ahmedre committed Nov 16, 2015
1 parent decf7d2 commit 28e031f
Showing 1 changed file with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.quran.labs.androidquran.util;

import com.crashlytics.android.Crashlytics;
import com.quran.labs.androidquran.BuildConfig;
import com.quran.labs.androidquran.data.Constants;
import com.quran.labs.androidquran.service.QuranDownloadService;
Expand Down Expand Up @@ -118,37 +117,50 @@ public void upgradePreferences() {
version = mPrefs.getInt(Constants.PREF_VERSION, 0);
}

if (version != 0 && version < 2672) {
// migrate preferences
setAppCustomLocation(mPrefs.getString(Constants.PREF_APP_LOCATION, null));

if (mPrefs.contains(Constants.PREF_SHOULD_FETCH_PAGES)) {
setShouldFetchPages(mPrefs.getBoolean(Constants.PREF_SHOULD_FETCH_PAGES, false));
}

if (mPrefs.contains(QuranDownloadService.PREF_LAST_DOWNLOAD_ERROR)) {
setLastDownloadError(
mPrefs.getString(QuranDownloadService.PREF_LAST_DOWNLOAD_ITEM, null),
mPrefs.getInt(QuranDownloadService.PREF_LAST_DOWNLOAD_ERROR, 0));
if (version != 0) {
if (version < 2672) {
// migrate preferences
setAppCustomLocation(mPrefs.getString(Constants.PREF_APP_LOCATION, null));

if (mPrefs.contains(Constants.PREF_SHOULD_FETCH_PAGES)) {
setShouldFetchPages(mPrefs.getBoolean(Constants.PREF_SHOULD_FETCH_PAGES, false));
}

if (mPrefs.contains(QuranDownloadService.PREF_LAST_DOWNLOAD_ERROR)) {
setLastDownloadError(
mPrefs.getString(QuranDownloadService.PREF_LAST_DOWNLOAD_ITEM, null),
mPrefs.getInt(QuranDownloadService.PREF_LAST_DOWNLOAD_ERROR, 0));
}

if (mPrefs.contains(Constants.PREF_ACTIVE_TRANSLATION)) {
setActiveTranslation(mPrefs.getString(Constants.PREF_ACTIVE_TRANSLATION, null));
}

mPrefs.edit()
.remove(Constants.PREF_VERSION)
.remove(Constants.PREF_APP_LOCATION)
.remove(Constants.PREF_SHOULD_FETCH_PAGES)
.remove(QuranDownloadService.PREF_LAST_DOWNLOAD_ERROR)
.remove(QuranDownloadService.PREF_LAST_DOWNLOAD_ITEM)
.remove(Constants.PREF_ACTIVE_TRANSLATION)
// these aren't migrated since they can be derived pretty easily
.remove("didPresentPermissionsRationale") // was renamed, removing old one
.remove(Constants.PREF_DEFAULT_IMAGES_DIR)
.remove(Constants.PREF_HAVE_UPDATED_TRANSLATIONS)
.remove(Constants.PREF_LAST_UPDATED_TRANSLATIONS)
.apply();
} else if (version < 2674) {
// explicitly an else - if we migrated via the above, we're okay. otherwise, we are in
// a bad state due to not crashing in 2.6.7-p2 (thus getting its incorrect behavior),
// and thus crashing on 2.6.7-p3 and above (where the bug was fixed). this works around
// this issue.
try {
getLastDownloadItemWithError();
getLastDownloadErrorCode();
} catch (Exception e) {
clearLastDownloadError();
}
}

if (mPrefs.contains(Constants.PREF_ACTIVE_TRANSLATION)) {
setActiveTranslation(mPrefs.getString(Constants.PREF_ACTIVE_TRANSLATION, null));
}

mPrefs.edit()
.remove(Constants.PREF_VERSION)
.remove(Constants.PREF_APP_LOCATION)
.remove(Constants.PREF_SHOULD_FETCH_PAGES)
.remove(QuranDownloadService.PREF_LAST_DOWNLOAD_ERROR)
.remove(QuranDownloadService.PREF_LAST_DOWNLOAD_ITEM)
.remove(Constants.PREF_ACTIVE_TRANSLATION)
// these aren't migrated since they can be derived pretty easily
.remove("didPresentPermissionsRationale") // was renamed, removing old one
.remove(Constants.PREF_DEFAULT_IMAGES_DIR)
.remove(Constants.PREF_HAVE_UPDATED_TRANSLATIONS)
.remove(Constants.PREF_LAST_UPDATED_TRANSLATIONS)
.apply();
}

// no matter which version we're upgrading from, make sure the app location is set
Expand Down

0 comments on commit 28e031f

Please sign in to comment.