Skip to content

Commit

Permalink
Merge pull request #7389 from brave/pr7376_make_yandex_default_androi…
Browse files Browse the repository at this point in the history
…d_1.19.x

Set Yandex as default (uplift to 1.19.x)
  • Loading branch information
kjozwiak authored Dec 9, 2020
2 parents 186eafe + c2513fe commit cd3a8d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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);
}
}

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 @@ -69,7 +69,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";

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

0 comments on commit cd3a8d2

Please sign in to comment.