From f36aad4194f91ef0532e5cf258953035bcec0306 Mon Sep 17 00:00:00 2001 From: serg Date: Tue, 23 Jun 2020 23:44:20 -0400 Subject: [PATCH 1/3] adds notification on Android browser upgrade --- android/brave_java_sources.gni | 1 + .../chrome/browser/BraveActivity.java | 30 ++++++ .../preferences/BravePreferenceKeys.java | 6 ++ ...BravePackageReplacedBroadcastReceiver.java | 5 + .../browser/upgrade/NotificationIntent.java | 92 +++++++++++++++++++ .../android/strings/android_brave_strings.grd | 6 ++ 6 files changed, 140 insertions(+) create mode 100644 android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java diff --git a/android/brave_java_sources.gni b/android/brave_java_sources.gni index 43ea439e9bed..9b9c03b82b1b 100644 --- a/android/brave_java_sources.gni +++ b/android/brave_java_sources.gni @@ -125,6 +125,7 @@ brave_java_sources = [ "../../brave/android/java/org/chromium/chrome/browser/toolbar/bottom/BraveSearchAccelerator.java", "../../brave/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayout.java", "../../brave/android/java/org/chromium/chrome/browser/upgrade/BravePackageReplacedBroadcastReceiver.java", + "../../brave/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java", "../../brave/android/java/org/chromium/chrome/browser/util/BraveDbUtil.java", "../../brave/android/java/org/chromium/chrome/browser/util/BraveReferrer.java", "../../brave/android/java/org/chromium/chrome/browser/util/PackageUtils.java", diff --git a/android/java/org/chromium/chrome/browser/BraveActivity.java b/android/java/org/chromium/chrome/browser/BraveActivity.java index 880d48ff8821..6e75d30ac2c6 100644 --- a/android/java/org/chromium/chrome/browser/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/BraveActivity.java @@ -15,6 +15,7 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; +import android.os.Bundle; import android.provider.Settings; import android.support.v7.app.AlertDialog; import android.text.TextUtils; @@ -26,6 +27,7 @@ import org.chromium.base.ApplicationStatus; import org.chromium.base.CommandLine; import org.chromium.base.ContextUtils; +import org.chromium.base.IntentUtils; import org.chromium.base.annotations.JNINamespace; import org.chromium.base.task.PostTask; import org.chromium.base.task.TaskTraits; @@ -39,6 +41,7 @@ import org.chromium.chrome.browser.notifications.BraveSetDefaultBrowserNotificationService; import org.chromium.chrome.browser.onboarding.OnboardingActivity; import org.chromium.chrome.browser.onboarding.OnboardingPrefManager; +import org.chromium.chrome.browser.preferences.BravePreferenceKeys; import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.settings.BraveRewardsPreferences; @@ -62,6 +65,8 @@ import org.chromium.chrome.browser.rate.RateUtils; import org.chromium.chrome.browser.preferences.SharedPreferencesManager; +import java.util.Calendar; + /** * Brave's extension for ChromeActivity */ @@ -481,4 +486,29 @@ public void performPreInflationStartup() { } super.performPreInflationStartup(); } + + @Override + protected @LaunchIntentDispatcher.Action int maybeDispatchLaunchIntent( + Intent intent, Bundle savedInstanceState) { + boolean notificationUpdate = IntentUtils.safeGetBooleanExtra( + intent, BravePreferenceKeys.BRAVE_UPDATE_EXTRA_PARAM, false); + if (notificationUpdate) { + SetUpdatePreferences(); + } + + return super.maybeDispatchLaunchIntent(intent, savedInstanceState); + } + + private void SetUpdatePreferences() { + Calendar currentTime = Calendar.getInstance(); + long milliSeconds = currentTime.getTimeInMillis(); + + SharedPreferences sharedPref = + getApplicationContext().getSharedPreferences( + BravePreferenceKeys.BRAVE_NOTIFICATION_PREF_NAME, 0); + SharedPreferences.Editor editor = sharedPref.edit(); + + editor.putLong(BravePreferenceKeys.BRAVE_MILLISECONDS_NAME, milliSeconds); + editor.apply(); + } } diff --git a/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java b/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java index 8e747b2ae8cc..08ddabd65987 100644 --- a/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java +++ b/android/java/org/chromium/chrome/browser/preferences/BravePreferenceKeys.java @@ -10,4 +10,10 @@ public final class BravePreferenceKeys { public static final String BRAVE_BOTTOM_TOOLBAR_SET_KEY = "brave_bottom_toolbar_enabled"; public static final String BRAVE_USE_CUSTOM_TABS = "use_custom_tabs"; public static final String BRAVE_APP_OPEN_COUNT = "brave_app_open_count"; + public static final String BRAVE_UPDATE_EXTRA_PARAM = + "org.chromium.chrome.browser.upgrade.UPDATE_NOTIFICATION_NEW"; + public static final String BRAVE_NOTIFICATION_PREF_NAME = + "org.chromium.chrome.browser.upgrade.NotificationUpdateTimeStampPreferences_New"; + public static final String BRAVE_MILLISECONDS_NAME = + "org.chromium.chrome.browser.upgrade.Milliseconds_New"; } \ No newline at end of file diff --git a/android/java/org/chromium/chrome/browser/upgrade/BravePackageReplacedBroadcastReceiver.java b/android/java/org/chromium/chrome/browser/upgrade/BravePackageReplacedBroadcastReceiver.java index dc223c3e30eb..645a0d371b2e 100644 --- a/android/java/org/chromium/chrome/browser/upgrade/BravePackageReplacedBroadcastReceiver.java +++ b/android/java/org/chromium/chrome/browser/upgrade/BravePackageReplacedBroadcastReceiver.java @@ -23,5 +23,10 @@ public final class BravePackageReplacedBroadcastReceiver extends BroadcastReceiv public void onReceive(final Context context, Intent intent) { if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) return; SharedPreferencesManager.getInstance().writeInt(BravePreferenceKeys.BRAVE_APP_OPEN_COUNT, 0); + try { + NotificationIntent.fireNotificationIfNecessary(context); + } catch (Exception exc) { + // Just ignore if we could not send a notification + } } } diff --git a/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java b/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java new file mode 100644 index 000000000000..c134aa9cdf38 --- /dev/null +++ b/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java @@ -0,0 +1,92 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.chromium.chrome.browser.upgrade; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Build; +import android.support.v4.app.NotificationCompat; +import android.view.View; + +import org.chromium.base.Log; +import org.chromium.base.ThreadUtils; +import org.chromium.chrome.R; +import org.chromium.chrome.browser.preferences.BravePreferenceKeys; + +import java.util.Arrays; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; + +/** + * Fires notification about new features. + */ +public class NotificationIntent { + private static final String TAG = "NotificationIntent"; + private static final String NOTIFICATION_TAG = "16c570a4-da7d-4c4e-8518-d2b7d6e41615"; + private static final String NOTIFICATION_CHANNEL_ID = "a79c3102-4183-4001-a553-ec3041bd0f49"; + private static final String URL = "https://brave.com/new-brave-22-percent-faster/"; + private static final List mWhitelistedRegionalLocales = Arrays.asList("en", "ru", "uk", "be", "pt", "fr"); + private static final int NOTIFICATION_ID = 732; + //private static final String NOTIFICATION_TITLE = "Brave update"; + //private static final String NOTIFICATION_TEXT = "The new Brave browser is 22% faster"; + + public static void fireNotificationIfNecessary(Context context) { + String notification_text = context.getString(R.string.update_notification_text); + if (!ShouldNotify(context)) { + return; + } + NotificationManager mNotificationManager = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, + "Channel for notifications", + NotificationManager.IMPORTANCE_DEFAULT); + mNotificationManager.createNotificationChannel(channel); + } + + NotificationCompat.Builder mBuilder = + new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID); + + // Create an intent that’ll be fired when a user taps the notification// + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL)); + intent.putExtra(BravePreferenceKeys.BRAVE_UPDATE_EXTRA_PARAM, true); + intent.setPackage(context.getPackageName()); + PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); + + mBuilder.setContentIntent(pendingIntent); + mBuilder.setAutoCancel(true); + + mBuilder.setSmallIcon(R.drawable.ic_chrome); + mBuilder.setContentTitle(context.getString(R.string.update_notification_title)); + mBuilder.setContentText(notification_text); + + mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, mBuilder.build()); + } + + public static boolean ShouldNotify(Context context) { + String deviceLanguage = Locale.getDefault().getLanguage(); + if (GetPreferences(context) != 0 + || !mWhitelistedRegionalLocales.contains(new Locale(deviceLanguage).getLanguage())) { + return false; + } + + return true; + } + + public static long GetPreferences(Context context) { + SharedPreferences sharedPref = context.getSharedPreferences(BravePreferenceKeys.BRAVE_NOTIFICATION_PREF_NAME, 0); + + return sharedPref.getLong(BravePreferenceKeys.BRAVE_MILLISECONDS_NAME, 0); + } +} diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index 15ed18188a22..e05dcb51369e 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -1158,6 +1158,12 @@ until they verify, or until 90 days have passed. Show suggested sites in autocomplete + + Brave update + + + The new Brave browser is faster + From 873a09762832dc6350af56ef6d7ca5809ae38543 Mon Sep 17 00:00:00 2001 From: samartnik Date: Wed, 24 Jun 2020 17:00:14 -0400 Subject: [PATCH 2/3] Added new strings, url and their translations --- .../chromium/chrome/browser/upgrade/NotificationIntent.java | 5 +++-- browser/ui/android/strings/android_brave_strings.grd | 4 ++-- .../strings/translations/android_brave_strings_de.xtb | 2 ++ .../strings/translations/android_brave_strings_es.xtb | 2 ++ .../strings/translations/android_brave_strings_ja.xtb | 2 ++ .../strings/translations/android_brave_strings_pl.xtb | 2 ++ .../strings/translations/android_brave_strings_pt-PT.xtb | 2 ++ .../strings/translations/android_brave_strings_ru.xtb | 2 ++ .../strings/translations/android_brave_strings_uk.xtb | 2 ++ 9 files changed, 19 insertions(+), 4 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java b/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java index c134aa9cdf38..7a42beaeb969 100644 --- a/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java +++ b/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java @@ -34,8 +34,8 @@ public class NotificationIntent { private static final String TAG = "NotificationIntent"; private static final String NOTIFICATION_TAG = "16c570a4-da7d-4c4e-8518-d2b7d6e41615"; private static final String NOTIFICATION_CHANNEL_ID = "a79c3102-4183-4001-a553-ec3041bd0f49"; - private static final String URL = "https://brave.com/new-brave-22-percent-faster/"; - private static final List mWhitelistedRegionalLocales = Arrays.asList("en", "ru", "uk", "be", "pt", "fr"); + private static final String URL = "https://support.brave.com/hc/en-us/articles/360045401211/"; + private static final List mWhitelistedRegionalLocales = Arrays.asList("en", "ru", "uk", "de", "pt", "pl", "ja", "es"); private static final int NOTIFICATION_ID = 732; //private static final String NOTIFICATION_TITLE = "Brave update"; //private static final String NOTIFICATION_TEXT = "The new Brave browser is 22% faster"; @@ -70,6 +70,7 @@ public static void fireNotificationIfNecessary(Context context) { mBuilder.setSmallIcon(R.drawable.ic_chrome); mBuilder.setContentTitle(context.getString(R.string.update_notification_title)); mBuilder.setContentText(notification_text); + mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notification_text)); mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, mBuilder.build()); } diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index e05dcb51369e..05d71f6f0031 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -1159,10 +1159,10 @@ until they verify, or until 90 days have passed. Show suggested sites in autocomplete - Brave update + Save Data Online - The new Brave browser is faster + Browse faster and block ads with Brave diff --git a/browser/ui/android/strings/translations/android_brave_strings_de.xtb b/browser/ui/android/strings/translations/android_brave_strings_de.xtb index c35360a70c41..f83505175fc0 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_de.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_de.xtb @@ -333,4 +333,6 @@ um das nächste Internet zu erleben. Vielen Dank, dass Sie Braves Entwickler darüber informiert haben, dass auf dieser Website ein Fehler auftritt. Wir werden unser Bestes tun, um ihn zu beheben! Fortgeschrittene Steuerung Ein Minimumguthaben von 25 BAT ist für die Verifizierung erforderlich. +Daten online speichern +Schneller surfen und Anzeigen blockieren mit Brave \ No newline at end of file diff --git a/browser/ui/android/strings/translations/android_brave_strings_es.xtb b/browser/ui/android/strings/translations/android_brave_strings_es.xtb index 2eeffdc5a1a1..76ef7458914e 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_es.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_es.xtb @@ -336,4 +336,6 @@ para apoyarlos. Gracias por informar a los desarrolladores de Brave sobre posibles errores en este sitio. ¡Haremos todo lo posible para arreglarlo! Controles avanzados Se requiere un saldo mínimo de 25 BAT para hacer la verificación. +Guardar datos en línea +Navegar más rápido y bloquear anuncios con Brave \ No newline at end of file diff --git a/browser/ui/android/strings/translations/android_brave_strings_ja.xtb b/browser/ui/android/strings/translations/android_brave_strings_ja.xtb index 9a8f84bdb38e..7a767436edb1 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_ja.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_ja.xtb @@ -335,4 +335,6 @@ このサイトの問題をBraveの開発者にお知らせいただき、ありがとうございます。最善を尽くしてその修正を行います! 高度なコントロール 照会するには最低25BATの残高が必要です。 +オンラインデータを保存 +Braveで高速ブラウジングし, 広告をブロックできる \ No newline at end of file diff --git a/browser/ui/android/strings/translations/android_brave_strings_pl.xtb b/browser/ui/android/strings/translations/android_brave_strings_pl.xtb index c425589c3472..4aa264f33447 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_pl.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_pl.xtb @@ -339,4 +339,6 @@ przez kolejne 90 dni lub do momentu zarejestrowania się twórców.Dziękujemy za poinformowanie deweloperów Brave, że coś jest nie tak z tą witryną. Dołożymy wszelkich starań, aby ją naprawić! Zaawansowane sterowanie Do weryfikacji wymagane jest minimalne saldo w wysokości 25 BAT. +Oszczędzaj transfer danych +Przeglądaj szybciej i blokuj reklamy z Brave \ No newline at end of file diff --git a/browser/ui/android/strings/translations/android_brave_strings_pt-PT.xtb b/browser/ui/android/strings/translations/android_brave_strings_pt-PT.xtb index 41878958d64b..0cb4b553deb9 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_pt-PT.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_pt-PT.xtb @@ -339,4 +339,6 @@ até que a verificação ocorra ou tenham decorrido 90 dias. Obrigado por comunicar aos desenvolvedores da Brave que há algo de errado com o site. Daremos o nosso melhor para o consertar. Controlos avançados É necessário um saldo mínimo de 25 MTD para a verificação. +Economize Dados Online +Navegue mais rápido e bloqueie anúncios online \ No newline at end of file diff --git a/browser/ui/android/strings/translations/android_brave_strings_ru.xtb b/browser/ui/android/strings/translations/android_brave_strings_ru.xtb index bc3b1f7feddc..bd5c8c9dd831 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_ru.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_ru.xtb @@ -336,4 +336,6 @@ Спасибо, что сообщили разработчикам Brave о неполадке на этом сайте. Мы сделаем все возможное, чтобы исправить ее! Расширенное управление Для проверки на балансе должно быть не менее 25 BAT. +Экономь на трафике +Загружай сайты быстрее и блокируй рекламу с Brave \ No newline at end of file diff --git a/browser/ui/android/strings/translations/android_brave_strings_uk.xtb b/browser/ui/android/strings/translations/android_brave_strings_uk.xtb index 0288257cb927..212ac0039580 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_uk.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_uk.xtb @@ -332,4 +332,6 @@ Дякуємо за повідомлення розробникам Brave щодо проблеми із цим сайтом. Ми постараємося її виправити! Розширені налаштування Для підтвердження необхідний мінімальний баланс у 25 BAT. +Заощаджуй на трафіку +Завантажуй сайти швидше та блокуй рекламу з Brave \ No newline at end of file From 97620df962e3d9a65478dd555f914e80b950c8af Mon Sep 17 00:00:00 2001 From: samartnik Date: Wed, 24 Jun 2020 18:16:26 -0400 Subject: [PATCH 3/3] Added French translation --- .../org/chromium/chrome/browser/upgrade/NotificationIntent.java | 2 +- .../android/strings/translations/android_brave_strings_fr.xtb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java b/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java index 7a42beaeb969..3e0fc127479d 100644 --- a/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java +++ b/android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java @@ -35,7 +35,7 @@ public class NotificationIntent { private static final String NOTIFICATION_TAG = "16c570a4-da7d-4c4e-8518-d2b7d6e41615"; private static final String NOTIFICATION_CHANNEL_ID = "a79c3102-4183-4001-a553-ec3041bd0f49"; private static final String URL = "https://support.brave.com/hc/en-us/articles/360045401211/"; - private static final List mWhitelistedRegionalLocales = Arrays.asList("en", "ru", "uk", "de", "pt", "pl", "ja", "es"); + private static final List mWhitelistedRegionalLocales = Arrays.asList("en", "ru", "uk", "de", "pt", "pl", "ja", "es", "fr"); private static final int NOTIFICATION_ID = 732; //private static final String NOTIFICATION_TITLE = "Brave update"; //private static final String NOTIFICATION_TEXT = "The new Brave browser is 22% faster"; diff --git a/browser/ui/android/strings/translations/android_brave_strings_fr.xtb b/browser/ui/android/strings/translations/android_brave_strings_fr.xtb index 1b6990ce3f44..c9d7cc5eb0f6 100644 --- a/browser/ui/android/strings/translations/android_brave_strings_fr.xtb +++ b/browser/ui/android/strings/translations/android_brave_strings_fr.xtb @@ -335,4 +335,6 @@ mois-ci... Merci d'avoir fait savoir aux développeurs de Brave qu'il y a quelque chose qui ne marche pas sur ce site. Nous ferons de notre mieux pour le réparer ! Commandes avancées Un solde minimum de 25 BAT est requis pour la vérification. +Economisez vos données mobiles +Naviguez plus rapidement et bloquez les pubs avec Brave \ No newline at end of file