Skip to content
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

Set Yandex as default #7376

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@
import org.chromium.components.bookmarks.BookmarkId;
import org.chromium.components.bookmarks.BookmarkType;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.ui.widget.Toast;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
* Brave's extension for ChromeActivity
Expand Down Expand Up @@ -113,6 +117,9 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
public static final String ANDROID_PACKAGE_NAME = "android";
public static final String BRAVE_BLOG_URL = "http://www.brave.com/blog";

private static final List<String> yandexRegions =
Arrays.asList("AM", "AZ", "BY", "KG", "KZ", "MD", "RU", "TJ", "TM", "UZ");

public BraveActivity() {
// Disable key checker to avoid asserts on Brave keys in debug
SharedPreferencesManager.getInstance().disableKeyCheckerForTesting();
Expand Down Expand Up @@ -217,6 +224,10 @@ public void finishNativeInitialization() {
int appOpenCount = SharedPreferencesManager.getInstance().readInt(BravePreferenceKeys.BRAVE_APP_OPEN_COUNT);
SharedPreferencesManager.getInstance().writeInt(BravePreferenceKeys.BRAVE_APP_OPEN_COUNT, appOpenCount + 1);

if (PackageUtils.isFirstInstall(this) && appOpenCount == 0) {
checkForYandexSE();
}

//set bg ads to off for existing and new installations
setBgBraveAdsDefaultOff();

Expand Down Expand Up @@ -312,6 +323,16 @@ public void finishNativeInitialization() {
}
}

private void checkForYandexSE() {
TemplateUrl yandexTemplateUrl =
BraveSearchEngineUtils.getTemplateUrlByShortName(OnboardingPrefManager.YANDEX);
String countryCode = Locale.getDefault().getCountry();
if (yandexRegions.contains(countryCode) && yandexTemplateUrl != null) {
BraveSearchEngineUtils.setDSEPrefs(yandexTemplateUrl, false);
BraveSearchEngineUtils.setDSEPrefs(yandexTemplateUrl, true);
SergeyZhukovsky marked this conversation as resolved.
Show resolved Hide resolved
}
}

private void checkForNotificationData() {
Intent notifIntent = getIntent();
if (notifIntent != null && notifIntent.getStringExtra(RetentionNotificationUtil.NOTIFICATION_TYPE) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class OnboardingPrefManager {
private static final String BING = "Bing";
private static final String STARTPAGE = "Startpage";
private static final String YAHOO = "Yahoo";
private static final String YANDEX = "Yandex";
public static final String YANDEX = "Yandex";
SergeyZhukovsky marked this conversation as resolved.
Show resolved Hide resolved

private OnboardingPrefManager() {
mSharedPreferences = ContextUtils.getAppSharedPreferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void refreshData() {
TemplateUrlService templateUrlService = TemplateUrlServiceFactory.get();
List<TemplateUrl> templateUrls = templateUrlService.getTemplateUrls();
TemplateUrl defaultSearchEngineTemplateUrl =
templateUrlService.getDefaultSearchEngineTemplateUrl();
BraveSearchEngineUtils.getTemplateUrlByShortName(BraveSearchEngineUtils.getDSEShortName(false));

for (TemplateUrl templateUrl : templateUrls) {
if (templateUrl.getIsPrepopulated()
Expand Down Expand Up @@ -114,7 +114,7 @@ private void setActions() {
@Override
public void onClick(View view) {
if (selectedSearchEngine == null) {
selectedSearchEngine = TemplateUrlServiceFactory.get().getDefaultSearchEngineTemplateUrl();
selectedSearchEngine = BraveSearchEngineUtils.getTemplateUrlByShortName(BraveSearchEngineUtils.getDSEShortName(false));
}
if (selectedSearchEngine != null) {
BraveSearchEngineUtils.setDSEPrefs(selectedSearchEngine, false);
Expand Down