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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan Henning 2019-05-07 17:21:01 +00:00
Родитель 9036a5ab11
Коммит b9a12131e0
5 изменённых файлов: 57 добавлений и 1 удалений

Просмотреть файл

@ -1,5 +1,8 @@
<?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"

Просмотреть файл

@ -155,6 +155,7 @@ public class GeckoPreferences
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";
@ -849,6 +850,12 @@ public class GeckoPreferences
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);
@ -1533,8 +1540,14 @@ public class GeckoPreferences
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);
}
}

Просмотреть файл

@ -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());
}
}

Просмотреть файл

@ -919,6 +919,7 @@ Picture-in-picture mini window -->
<!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">

Просмотреть файл

@ -659,6 +659,7 @@
<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>