Bug 1494026 - Part 1: Add link to OS app notification settings. r=VladBaicu
authorJan Henning <jh+bugzilla@buttercookie.de>
Tue, 07 May 2019 17:21:01 +0000
changeset 531767 a66cab570864911c2607359e76d510a43fbbeb4f
parent 531766 0cca2f068966246ac6468255a87e0a1b4cf64dc4
child 531768 6d2d7856e468e04234f4efad320fa26d222a2eb9
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu
bugs1494026
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494026 - Part 1: Add link to OS app notification settings. r=VladBaicu Starting from Android O, more fine-grained control over which notifications should be displayed is available through Android's notification channel system. To aid discoverability, we add a link to the corresponding settings screen from inside our own settings menu. Differential Revision: https://phabricator.services.mozilla.com/D29973
mobile/android/app/src/main/res/xml/preferences_notifications.xml
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
mobile/android/base/java/org/mozilla/gecko/preferences/NotificationSettingsLinkPreference.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
--- a/mobile/android/app/src/main/res/xml/preferences_notifications.xml
+++ b/mobile/android/app/src/main/res/xml/preferences_notifications.xml
@@ -1,10 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+    <org.mozilla.gecko.preferences.NotificationSettingsLinkPreference
+        android:key="android.not_a_preference.notifications.settings_link"
+        android:title="@string/pref_notification_settings_link" />
     <SwitchPreference android:key="android.not_a_preference.notifications.whats_new"
         android:title="@string/pref_whats_new_notification"
         android:summary="@string/pref_whats_new_notification_summary"
         android:defaultValue="true" />
     <SwitchPreference android:key="android.not_a_preference.notifications.features.tips"
         android:title="@string/pref_feature_tips_notification"
         android:summary="@string/pref_feature_tips_notification_summary"
         android:defaultValue="true" />
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -150,16 +150,17 @@ public class GeckoPreferences
     private static final String PREFS_SCREEN_ADVANCED = NON_PREF_PREFIX + "advanced_screen";
     public static final String PREFS_HOMEPAGE = NON_PREF_PREFIX + "homepage";
     public static final String PREFS_HOMEPAGE_FOR_EVERY_NEW_TAB = NON_PREF_PREFIX + "newtab.load_homepage";
     public static final String PREFS_HOMEPAGE_PARTNER_COPY = GeckoPreferences.PREFS_HOMEPAGE + ".partner";
     public static final String PREFS_HISTORY_SAVED_SEARCH = NON_PREF_PREFIX + "search.search_history.enabled";
     private static final String PREFS_FAQ_LINK = NON_PREF_PREFIX + "faq.link";
     private static final String PREFS_FEEDBACK_LINK = NON_PREF_PREFIX + "feedback.link";
     private static final String PREFS_SCREEN_NOTIFICATIONS = NON_PREF_PREFIX + "notifications_screen";
+    private static final String PREFS_NOTIFICATIONS_SETTINGS_LINK = NON_PREF_PREFIX + "notifications.settings_link";
     public static final String PREFS_NOTIFICATIONS_WHATS_NEW = NON_PREF_PREFIX + "notifications.whats_new";
     public static final String PREFS_NOTIFICATIONS_FEATURES_TIPS = NON_PREF_PREFIX + "notifications.features.tips";
     public static final String PREFS_APP_UPDATE_LAST_BUILD_ID = "app.update.last_build_id";
     public static final String PREFS_READ_PARTNER_CUSTOMIZATIONS_PROVIDER = NON_PREF_PREFIX + "distribution.read_partner_customizations_provider";
     public static final String PREFS_READ_PARTNER_BOOKMARKS_PROVIDER = NON_PREF_PREFIX + "distribution.read_partner_bookmarks_provider";
     public static final String PREFS_CUSTOM_TABS = NON_PREF_PREFIX + "customtabs_58";
     public static final String PREFS_CATEGORY_EXPERIMENTAL_FEATURES = NON_PREF_PREFIX + "category_experimental";
     public static final String PREFS_COMPACT_TABS = NON_PREF_PREFIX + "compact_tabs";
@@ -844,16 +845,22 @@ public class GeckoPreferences
                         continue;
                     }
                 } else if (PREFS_COMPACT_TABS.equals(key)) {
                     if (HardwareUtils.isTablet()) {
                         preferences.removePreference(pref);
                         i--;
                         continue;
                     }
+                } else if (PREFS_NOTIFICATIONS_SETTINGS_LINK.equals(key)) {
+                    if (!showNotificationSettingsLink()) {
+                        preferences.removePreference(pref);
+                        i--;
+                        continue;
+                    }
                 } else if (PREFS_NOTIFICATIONS_WHATS_NEW.equals(key)) {
                     if (!SwitchBoard.isInExperiment(this, Experiments.WHATSNEW_NOTIFICATION)) {
                         preferences.removePreference(pref);
                         i--;
                         continue;
                     }
                 } else if (PREFS_NOTIFICATIONS_FEATURES_TIPS.equals(key)) {
                     final boolean isLeanplumAvailable = MmaDelegate.isMmaExperimentEnabled(this);
@@ -1528,13 +1535,19 @@ public class GeckoPreferences
         return isHealthReportEnabled && isInMmaExperiment && areMmaMessagesAllowed;
     }
 
     public static boolean isHealthReportEnabled(Context context) {
         // Health Report is enabled by default so we'll return true if the preference is not found
         return GeckoPreferences.getBooleanPref(context, PREFS_HEALTHREPORT_UPLOAD_ENABLED, true);
     }
 
+    private static boolean showNotificationSettingsLink() {
+        // Notification channels are available starting from Oreo.
+        return AppConstants.Versions.feature26Plus;
+    }
+
     private static boolean haveNotificationsPreferences(@NonNull Context context) {
-        return SwitchBoard.isInExperiment(context, Experiments.WHATSNEW_NOTIFICATION) ||
+        return showNotificationSettingsLink() ||
+                SwitchBoard.isInExperiment(context, Experiments.WHATSNEW_NOTIFICATION) ||
                 MmaDelegate.isMmaExperimentEnabled(context);
     }
 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/NotificationSettingsLinkPreference.java
@@ -0,0 +1,38 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * 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.mozilla.gecko.preferences;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.Intent;
+import android.preference.Preference;
+import android.provider.Settings;
+import android.util.AttributeSet;
+
+/**
+ * On Android O and following, this will open the app's OS notification settings when clicked on.
+ */
+public class NotificationSettingsLinkPreference extends Preference {
+    public NotificationSettingsLinkPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+    public NotificationSettingsLinkPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    protected void onClick() {
+        final Context context = getContext();
+        final Intent intent = getLinkIntent(context);
+        context.startActivity(intent);
+    }
+
+    @TargetApi(26)
+    private Intent getLinkIntent(final Context context) {
+        return new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
+                .putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
+    }
+}
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -914,16 +914,17 @@ See also https://bug1409261.bmoattachmen
 
 <!-- Used by accessibility services to identify the play/pause buttons shown in the
 Picture-in-picture mini window -->
 <!ENTITY pip_play_button_title "Play">
 <!ENTITY pip_play_button_description "Resume playing">
 <!ENTITY pip_pause_button_title "Pause">
 <!ENTITY pip_pause_button_description "Pause playing">
 
+<!ENTITY pref_notification_settings_link "Manage notification settings">
 <!-- Notification channels names -->
 <!ENTITY default_notification_channel2 "Browser">
 <!ENTITY mls_notification_channel "&vendorShortName; Location Service">
 <!ENTITY download_notification_channel "Downloads">
 <!ENTITY media_notification_channel2 "Sound and video">
 <!-- These push notifications come without a specific channel and/or name from Leanplum -->
 <!ENTITY leanplum_default_notifications_channel2 "&vendorShortName; tips and tricks">
 <!ENTITY updater_notification_channel "App updates">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -654,16 +654,17 @@
   <string name="pwa_onboarding_sumo">&pwa_onboarding_sumo;</string>
   <string name="pwa_continue_to_website">&pwa_continue_to_website;</string>
 
   <string name="pip_play_button_title">&pip_play_button_title;</string>
   <string name="pip_play_button_description">&pip_play_button_description;</string>
   <string name="pip_pause_button_title">&pip_pause_button_title;</string>
   <string name="pip_pause_button_description">&pip_pause_button_description;</string>
 
+  <string name="pref_notification_settings_link">&pref_notification_settings_link;</string>
   <string name="default_notification_channel2">&default_notification_channel2;</string>
   <string name="mls_notification_channel">&mls_notification_channel;</string>
   <string name="media_notification_channel2">&media_notification_channel2;</string>
   <string name="download_notification_channel">&download_notification_channel;</string>
   <string name="leanplum_default_notifications_channel2">&leanplum_default_notifications_channel2;</string>
   <string name="updater_notification_channel">&updater_notification_channel;</string>
   <string name="synced_tabs_notification_channel">&synced_tabs_notification_channel;</string>
   <string name="site_notifications_channel">&site_notifications_channel;</string>