Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7bbaf03 authored by Danny Baumann's avatar Danny Baumann Committed by Steve Kondik
Browse files

Move smart dialer initialization to onStart().

The SmartDialCursorLoader expects the SmartDialPrefix map to be
initialized when it's created. As
- the loader is initialized in SmartDialSearchFragment's onStart and
- the fragment's onStart is called asynchronously after the activity's
  onStart and
- the map initialization happens in
  SmartDialPrefix.initializeNanpSettings() and
- the above method is currently called in the activity's onResume()

we have a race condition between the activity's onResume() and the
fragment's onStart() (at least when processing a dial intent, which is
what causes the dialpad fragment to be immediately shown).

Fix that race condition by moving the initialization into the activity's
onStart() and running it before calling the super method to ensure it
happens before fragments are started.

JIRA:NIGHTLIES-760
Change-Id: I9767cbba3b177fdd5b1de86914cb1e40d20835ab
parent 99f56895
Loading
Loading
Loading
Loading
+24 −19
Original line number Original line Diff line number Diff line
@@ -492,6 +492,30 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        });
        });
    }
    }


    @Override
    protected void onStart() {
        // make this call on start in case user changed t9 locale in settings
        SmartDialPrefix.initializeNanpSettings(this);

        // if locale has changed since last time, refresh the smart dial db
        Locale locale = SettingsUtil.getT9SearchInputLocale(this);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String prevLocale = prefs.getString(PREF_LAST_T9_LOCALE, null);

        if (!TextUtils.equals(locale.toString(), prevLocale)) {
            mDialerDatabaseHelper.recreateSmartDialDatabaseInBackground();
            if (mDialpadFragment != null) {
                mDialpadFragment.refreshKeypad();
            }

            prefs.edit().putString(PREF_LAST_T9_LOCALE, locale.toString()).apply();
        } else {
            mDialerDatabaseHelper.startSmartDialUpdateThread();
        }

        super.onStart();
    }

    @Override
    @Override
    protected void onResume() {
    protected void onResume() {
        super.onResume();
        super.onResume();
@@ -520,25 +544,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        updateFloatingActionButtonControllerAlignment(false /* animate */);
        updateFloatingActionButtonControllerAlignment(false /* animate */);
        setConferenceDialButtonImage(false);
        setConferenceDialButtonImage(false);
        setConferenceDialButtonVisibility(true);
        setConferenceDialButtonVisibility(true);

        // make this call on resume in case user changed t9 locale in settings
        SmartDialPrefix.initializeNanpSettings(this);

        // if locale has changed since last time, refresh the smart dial db
        Locale locale = SettingsUtil.getT9SearchInputLocale(this);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String prevLocale = prefs.getString(PREF_LAST_T9_LOCALE, null);

        if (!TextUtils.equals(locale.toString(), prevLocale)) {
            mDialerDatabaseHelper.recreateSmartDialDatabaseInBackground();
            if (mDialpadFragment != null)
                mDialpadFragment.refreshKeypad();

            prefs.edit().putString(PREF_LAST_T9_LOCALE, locale.toString()).apply();
        }
        else {
            mDialerDatabaseHelper.startSmartDialUpdateThread();
        }
    }
    }


    @Override
    @Override