From 00f386cca2185cef5a1ca187051534b6f2deadca Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 15 Jan 2021 07:50:35 +0000 Subject: [PATCH] Fixes custom Brave ad notifications should not be shown on Dev channel builds --- common/brave_channel_info.cc | 11 +++++++---- common/brave_channel_info.h | 2 +- components/brave_ads/browser/ads_service_impl.cc | 12 ++++-------- .../brave_ads/browser/notification_helper_android.cc | 8 ++++++-- .../brave_ads/browser/notification_helper_linux.cc | 2 +- .../brave_ads/browser/notification_helper_mac.mm | 2 +- .../brave_ads/browser/notification_helper_win.cc | 2 +- .../ads/ad_notifications/ad_notifications.cc | 6 ++++-- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/common/brave_channel_info.cc b/common/brave_channel_info.cc index 8c99fe720f41..4a29595706d4 100644 --- a/common/brave_channel_info.cc +++ b/common/brave_channel_info.cc @@ -23,10 +23,13 @@ std::string GetChannelName() { #endif // !OFFICIAL_BUILD } -bool IsDevOrCanaryBuild() { - return chrome::GetChannel() == version_info::Channel::DEV || - chrome::GetChannel() == version_info::Channel::CANARY || - chrome::GetChannel() == version_info::Channel::UNKNOWN; +bool IsNightlyOrDeveloperBuild() { +#if defined(OFFICIAL_BUILD) + return chrome::GetChannel() == version_info::Channel::CANARY || + chrome::GetChannel() == version_info::Channel::UNKNOWN; +#else // OFFICIAL_BUILD + return true; +#endif // !OFFICIAL_BUILD } } // namespace brave diff --git a/common/brave_channel_info.h b/common/brave_channel_info.h index 9b42a72b050e..be746088b834 100644 --- a/common/brave_channel_info.h +++ b/common/brave_channel_info.h @@ -11,7 +11,7 @@ namespace brave { std::string GetChannelName(); -bool IsDevOrCanaryBuild(); +bool IsNightlyOrDeveloperBuild(); } diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 0182ece741cf..c3e965c6506f 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -661,7 +661,7 @@ void AdsServiceImpl::OnInitialize( is_initialized_ = true; - if (!brave::IsDevOrCanaryBuild()) { + if (!brave::IsNightlyOrDeveloperBuild()) { SetAdsServiceForNotificationHandler(); } @@ -1216,10 +1216,6 @@ void AdsServiceImpl::OnGetAdsHistory( } bool AdsServiceImpl::CanShowBackgroundNotifications() const { - if (brave::IsDevOrCanaryBuild()) { - return true; - } - return NotificationHelper::GetInstance()->CanShowBackgroundNotifications(); } @@ -1732,7 +1728,7 @@ std::string AdsServiceImpl::LoadDataResourceAndDecompressIfNeeded( // types of notification.h void AdsServiceImpl::ShowNotification( const ads::AdNotificationInfo& ad_notification) { - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { auto notification = CreateAdNotification(ad_notification); std::unique_ptr platform_bridge = @@ -1751,7 +1747,7 @@ void AdsServiceImpl::ShowNotification( void AdsServiceImpl::StartNotificationTimeoutTimer( const std::string& uuid) { #if defined(OS_ANDROID) - if (!brave::IsDevOrCanaryBuild()) { + if (!brave::IsNightlyOrDeveloperBuild()) { return; } #endif @@ -1792,7 +1788,7 @@ bool AdsServiceImpl::ShouldShowNotifications() { void AdsServiceImpl::CloseNotification( const std::string& uuid) { - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { std::unique_ptr platform_bridge = std::make_unique(profile_); platform_bridge->Close(profile_, uuid); diff --git a/components/brave_ads/browser/notification_helper_android.cc b/components/brave_ads/browser/notification_helper_android.cc index 42e997e59185..2a7ae46b24c5 100644 --- a/components/brave_ads/browser/notification_helper_android.cc +++ b/components/brave_ads/browser/notification_helper_android.cc @@ -34,7 +34,7 @@ NotificationHelperAndroid::NotificationHelperAndroid() = default; NotificationHelperAndroid::~NotificationHelperAndroid() = default; bool NotificationHelperAndroid::ShouldShowNotifications() { - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { return true; } @@ -58,7 +58,7 @@ bool NotificationHelperAndroid::ShowMyFirstAdNotification() { return false; } - const bool use_custom_notifications = brave::IsDevOrCanaryBuild(); + const bool use_custom_notifications = brave::IsNightlyOrDeveloperBuild(); JNIEnv* env = base::android::AttachCurrentThread(); Java_BraveAdsSignupDialog_enqueueOnboardingNotificationNative( @@ -69,6 +69,10 @@ bool NotificationHelperAndroid::ShowMyFirstAdNotification() { } bool NotificationHelperAndroid::CanShowBackgroundNotifications() const { + if (brave::IsNightlyOrDeveloperBuild()) { + return true; + } + JNIEnv* env = base::android::AttachCurrentThread(); return Java_BraveAdsSignupDialog_showAdsInBackground(env); } diff --git a/components/brave_ads/browser/notification_helper_linux.cc b/components/brave_ads/browser/notification_helper_linux.cc index 4599a2213469..cde70ae8e0b8 100644 --- a/components/brave_ads/browser/notification_helper_linux.cc +++ b/components/brave_ads/browser/notification_helper_linux.cc @@ -21,7 +21,7 @@ bool NotificationHelperLinux::ShouldShowNotifications() { return false; } - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { return true; } diff --git a/components/brave_ads/browser/notification_helper_mac.mm b/components/brave_ads/browser/notification_helper_mac.mm index 86ab98739086..1cc50ee83abe 100644 --- a/components/brave_ads/browser/notification_helper_mac.mm +++ b/components/brave_ads/browser/notification_helper_mac.mm @@ -31,7 +31,7 @@ return false; } - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { return true; } diff --git a/components/brave_ads/browser/notification_helper_win.cc b/components/brave_ads/browser/notification_helper_win.cc index 553c7e8b6c80..fbd6fc7ec9de 100644 --- a/components/brave_ads/browser/notification_helper_win.cc +++ b/components/brave_ads/browser/notification_helper_win.cc @@ -71,7 +71,7 @@ bool NotificationHelperWin::ShouldShowNotifications() { return false; } - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc index be5fc0b302dc..3f101e8fa929 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc @@ -189,9 +189,10 @@ uint64_t AdNotifications::Count() const { #if defined(OS_ANDROID) void AdNotifications::RemoveAllAfterReboot() { - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { return; } + database::table::AdEvents database_table; database_table.GetAll([=]( const Result result, @@ -217,9 +218,10 @@ void AdNotifications::RemoveAllAfterReboot() { } void AdNotifications::RemoveAllAfterUpdate() { - if (brave::IsDevOrCanaryBuild()) { + if (brave::IsNightlyOrDeveloperBuild()) { return; } + const std::string current_version_code = base::android::BuildInfo::GetInstance()->package_version_code();