Skip to content

Commit

Permalink
Fixes a crash on Quick Search on Android when TemplateUrlService is n…
Browse files Browse the repository at this point in the history
…ot loaded yet (uplift to 1.74.x) (#26955)

Uplift of #26940 (squashed) to beta
  • Loading branch information
brave-builds authored Dec 10, 2024
1 parent b2b3d06 commit 37f9603
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 12 additions & 0 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
import org.chromium.chrome.browser.rewards.adaptive_captcha.AdaptiveCaptchaHelper;
import org.chromium.chrome.browser.safe_browsing.SafeBrowsingBridge;
import org.chromium.chrome.browser.safe_browsing.SafeBrowsingState;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.set_default_browser.BraveSetDefaultBrowserUtils;
import org.chromium.chrome.browser.set_default_browser.OnBraveSetDefaultBrowserListener;
import org.chromium.chrome.browser.settings.BraveNewsPreferencesV2;
Expand Down Expand Up @@ -2582,6 +2583,17 @@ public void onClick(View v) {
}
});

Runnable onQuickSearchEnginesReady =
() -> {
if (isActivityFinishingOrDestroyed()) return;

quickSearchEnginesReady(recyclerView, keypadHeight);
};
TemplateUrlServiceFactory.getForProfile(getCurrentProfile())
.runWhenLoaded(onQuickSearchEnginesReady);
}

private void quickSearchEnginesReady(RecyclerView recyclerView, int keypadHeight) {
List<QuickSearchEnginesModel> searchEngines =
QuickSearchEnginesUtil.getQuickSearchEnginesForView(getCurrentProfile());
QuickSearchEnginesModel leoQuickSearchEnginesModel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.quick_search_engines.ItemTouchHelperCallback;
import org.chromium.chrome.browser.quick_search_engines.utils.QuickSearchEnginesUtil;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.settings.BravePreferenceFragment;
import org.chromium.chrome.browser.util.ImageUtils;

Expand Down Expand Up @@ -137,9 +138,16 @@ public ObservableSupplier<String> getPageTitle() {
}

private void refreshData() {
List<QuickSearchEnginesModel> quickSearchEngines =
QuickSearchEnginesUtil.getQuickSearchEnginesForSettings(getProfile());
setRecyclerViewData(quickSearchEngines);
Runnable onQuickSearchEnginesReady =
() -> {
if (isRemoving() || isDetached()) return;

List<QuickSearchEnginesModel> quickSearchEngines =
QuickSearchEnginesUtil.getQuickSearchEnginesForSettings(getProfile());
setRecyclerViewData(quickSearchEngines);
};
TemplateUrlServiceFactory.getForProfile(getProfile())
.runWhenLoaded(onQuickSearchEnginesReady);
}

private void setRecyclerViewData(List<QuickSearchEnginesModel> searchEngines) {
Expand Down

0 comments on commit 37f9603

Please sign in to comment.