Skip to content

Commit

Permalink
Android: setting bg brave ads off
Browse files Browse the repository at this point in the history
  • Loading branch information
gdregalo committed Apr 23, 2020
1 parent 4ab7000 commit 8296d3b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions android/java/org/chromium/chrome/browser/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8296d3b

Please sign in to comment.