[Android] Honor Brave Rewards disabled-by-policy pref (#35651)
brave_rewards::IsDisabledByPolicy() was hardcoded to return false on Android regardless of the managed kDisabledByPolicy pref, so every native call site that gates on brave_rewards::IsSupported() failed to suppress for Brave Origin subscribers (and enterprise admins setting the BraveRewardsDisabled policy). Symptoms fixed: - Ads service kept initializing on Android for Origin profiles (AdsServiceFactory::GetForProfile gates on IsSupported). - NTP sponsored background images and sponsored rich-media takeover rendered (downstream of the ads service via ViewCounterService). - DAY_10 / DAY_30 / DAY_35 Rewards retention notifications fired (RetentionNotificationPublisher gates on rewardsNativeWorker .isSupported). Java-side Rewards UI surfaces were already correctly gated via BraveRewardsPolicy.isDisabledByPolicy(profile) and are unaffected. Also decouples BraveVpnUtils.isRegionSupported() from BraveRewardsNativeWorker.isSupported() — otherwise the guard flip would cause VPN UI to hide for any profile where Rewards is policy-disabled as a side effect. Added BraveVpnNativeWorker.isSupportedRegion that does the OFAC region check directly via brave_l10n. Resolves: https://github.com/brave/brave-browser/issues/54703
This commit is contained in:
@@ -176,6 +176,10 @@ public class BraveVpnNativeWorker {
|
||||
return BraveVpnNativeWorkerJni.get().isPurchasedUser(mNativeBraveVpnNativeWorker);
|
||||
}
|
||||
|
||||
public boolean isSupportedRegion() {
|
||||
return BraveVpnNativeWorkerJni.get().isSupportedRegion(mNativeBraveVpnNativeWorker);
|
||||
}
|
||||
|
||||
public void getSubscriberCredentialV12() {
|
||||
BraveVpnNativeWorkerJni.get().getSubscriberCredentialV12(mNativeBraveVpnNativeWorker);
|
||||
}
|
||||
@@ -239,6 +243,8 @@ public class BraveVpnNativeWorker {
|
||||
|
||||
boolean isPurchasedUser(long nativeBraveVpnNativeWorker);
|
||||
|
||||
boolean isSupportedRegion(long nativeBraveVpnNativeWorker);
|
||||
|
||||
void getSubscriberCredentialV12(long nativeBraveVpnNativeWorker);
|
||||
|
||||
void reportBackgroundP3A(
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.chromium.base.ContextUtils;
|
||||
import org.chromium.base.Log;
|
||||
import org.chromium.brave_vpn.mojom.BraveVpnConstants;
|
||||
import org.chromium.brave_vpn.mojom.Region;
|
||||
import org.chromium.chrome.browser.BraveRewardsNativeWorker;
|
||||
import org.chromium.chrome.browser.vpn.BraveVpnNativeWorker;
|
||||
import org.chromium.chrome.browser.vpn.activities.BraveVpnProfileActivity;
|
||||
import org.chromium.chrome.browser.vpn.activities.BraveVpnSupportActivity;
|
||||
@@ -310,8 +309,8 @@ public class BraveVpnUtils {
|
||||
}
|
||||
|
||||
private static boolean isRegionSupported() {
|
||||
BraveRewardsNativeWorker braveRewardsNativeWorker = BraveRewardsNativeWorker.getInstance();
|
||||
return (braveRewardsNativeWorker != null && braveRewardsNativeWorker.isSupported());
|
||||
BraveVpnNativeWorker braveVpnNativeWorker = BraveVpnNativeWorker.getInstance();
|
||||
return braveVpnNativeWorker != null && braveVpnNativeWorker.isSupportedRegion();
|
||||
}
|
||||
|
||||
public static boolean isVpnFeatureSupported(Context context) {
|
||||
|
||||
@@ -129,6 +129,10 @@ specific_include_rules = {
|
||||
"brave_local_state_prefs\.cc": [
|
||||
"!brave/components/l10n/common/prefs.h",
|
||||
],
|
||||
"brave_vpn_native_worker\.cc": [
|
||||
"!brave/components/l10n/common/locale_util.h",
|
||||
"!brave/components/l10n/common/ofac_sanction_util.h",
|
||||
],
|
||||
"brave_browser_process_impl\.cc": [
|
||||
"+brave/components/brave_component_updater/browser/brave_component_updater_delegate.h",
|
||||
"+brave/components/brave_component_updater/browser/local_data_files_service.h",
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "base/values.h"
|
||||
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
|
||||
#include "brave/components/brave_vpn/browser/brave_vpn_service.h"
|
||||
#include "brave/components/l10n/common/locale_util.h"
|
||||
#include "brave/components/l10n/common/ofac_sanction_util.h"
|
||||
#include "chrome/android/chrome_jni_headers/BraveVpnNativeWorker_jni.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/profiles/profile_manager.h"
|
||||
@@ -260,6 +262,11 @@ void BraveVpnNativeWorker::ReloadPurchasedState(JNIEnv* env) {
|
||||
}
|
||||
}
|
||||
|
||||
bool BraveVpnNativeWorker::IsSupportedRegion(JNIEnv* env) {
|
||||
return !brave_l10n::IsISOCountryCodeOFACSanctioned(
|
||||
brave_l10n::GetDefaultISOCountryCodeString());
|
||||
}
|
||||
|
||||
void BraveVpnNativeWorker::ReportForegroundP3A(JNIEnv* env) {
|
||||
BraveVpnService* brave_vpn_service = GetBraveVpnService();
|
||||
if (brave_vpn_service) {
|
||||
|
||||
@@ -94,6 +94,8 @@ class BraveVpnNativeWorker {
|
||||
|
||||
jboolean IsPurchasedUser(JNIEnv* env);
|
||||
|
||||
bool IsSupportedRegion(JNIEnv* env);
|
||||
|
||||
void ReportForegroundP3A(JNIEnv* env);
|
||||
void ReportBackgroundP3A(JNIEnv* env,
|
||||
jlong session_start_time_ms,
|
||||
|
||||
@@ -57,6 +57,7 @@ if (enable_brave_vpn) {
|
||||
]
|
||||
brave_browser_brave_vpn_deps += [
|
||||
"//brave/build/android:jni_headers",
|
||||
"//brave/components/l10n/common",
|
||||
"//mojo/public/cpp/bindings",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "brave/components/brave_rewards/core/pref_names.h"
|
||||
#include "brave/components/l10n/common/locale_util.h"
|
||||
#include "brave/components/l10n/common/ofac_sanction_util.h"
|
||||
#include "build/build_config.h"
|
||||
@@ -19,22 +20,14 @@
|
||||
#include "brave/components/brave_rewards/core/features.h"
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
#if !BUILDFLAG(IS_ANDROID)
|
||||
#include "brave/components/brave_rewards/core/pref_names.h"
|
||||
#endif // !BUILDFLAG(IS_ANDROID)
|
||||
|
||||
namespace brave_rewards {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsDisabledByPolicy(PrefService* prefs) {
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
return false;
|
||||
#else
|
||||
DCHECK(prefs);
|
||||
return prefs->IsManagedPreference(prefs::kDisabledByPolicy) &&
|
||||
prefs->GetBoolean(prefs::kDisabledByPolicy);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsDisabledByFeature() {
|
||||
|
||||
Reference in New Issue
Block a user