diff --git a/android/java/org/chromium/chrome/browser/BraveActivity.java b/android/java/org/chromium/chrome/browser/BraveActivity.java index 5693b4af44b1..6bff24883c1b 100644 --- a/android/java/org/chromium/chrome/browser/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/BraveActivity.java @@ -12,6 +12,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.provider.Settings; @@ -37,6 +38,7 @@ import org.chromium.chrome.browser.onboarding.OnboardingPrefManager; import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.PrefServiceBridge; +import org.chromium.chrome.browser.settings.BraveRewardsPreferences; import org.chromium.chrome.browser.settings.BraveSearchEngineUtils; import org.chromium.chrome.browser.share.ShareDelegate; import org.chromium.chrome.browser.tab.Tab; @@ -187,6 +189,9 @@ public void finishNativeInitialization() { int appOpenCount = ContextUtils.getAppSharedPreferences().getInt(BackgroundImagesPreferences.PREF_APP_OPEN_COUNT, 0); BackgroundImagesPreferences.setOnPreferenceValue(BackgroundImagesPreferences.PREF_APP_OPEN_COUNT , appOpenCount + 1); + //set bg ads to off for existing and new installations + setBgBraveAdsDefaultOff(); + Context app = ContextUtils.getApplicationContext(); if (null != app && (this instanceof ChromeTabbedActivity)) { mBraveSyncWorker = new BraveSyncWorker(app); @@ -413,4 +418,23 @@ public void onActivityResult (int requestCode, int resultCode, } super.onActivityResult(requestCode, resultCode, data); } + + /** + * Disable background ads on Android. Issue #8641. + */ + private void setBgBraveAdsDefaultOff() { + SharedPreferences sharedPreferences = + ContextUtils.getAppSharedPreferences(); + boolean exists = sharedPreferences.contains( + BraveRewardsPreferences.PREF_ADS_SWITCH_DEFAULT_HAS_BEEN_SET); + if (!exists) { + SharedPreferences.Editor sharedPreferencesEditor = + sharedPreferences.edit(); + sharedPreferencesEditor.putBoolean( + BraveRewardsPreferences.PREF_ADS_SWITCH, false); + sharedPreferencesEditor.putBoolean( + BraveRewardsPreferences.PREF_ADS_SWITCH_DEFAULT_HAS_BEEN_SET, true); + sharedPreferencesEditor.apply(); + } + } } diff --git a/android/java/org/chromium/chrome/browser/settings/BraveRewardsPreferences.java b/android/java/org/chromium/chrome/browser/settings/BraveRewardsPreferences.java index 5de884664d25..087a9b7e8ddf 100644 --- a/android/java/org/chromium/chrome/browser/settings/BraveRewardsPreferences.java +++ b/android/java/org/chromium/chrome/browser/settings/BraveRewardsPreferences.java @@ -23,7 +23,10 @@ */ public class BraveRewardsPreferences extends BravePreferenceFragment implements OnPreferenceChangeListener, BraveRewardsObserver { - private static final String PREF_ADS_SWITCH = "ads_switch"; + public static final String PREF_ADS_SWITCH = "ads_switch"; + + // flag, if exists: default state (off) for background Brave ads has been set + public static final String PREF_ADS_SWITCH_DEFAULT_HAS_BEEN_SET = "ads_switch_default_set"; private ChromeSwitchPreference mAdsSwitch;