File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
addon/notifications/pages/settings
core/pushnotifications/providers Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ export class AddonNotificationsSettingsPage implements OnDestroy {
5555 @Optional ( ) private svComponent : CoreSplitViewComponent ) {
5656
5757 this . notifPrefsEnabled = notificationsProvider . isNotificationPreferencesEnabled ( ) ;
58- this . canChangeSound = localNotificationsProvider . isAvailable ( ) && ! appProvider . isDesktop ( ) ;
58+ this . canChangeSound = localNotificationsProvider . canDisableSound ( ) ;
59+
5960 if ( this . canChangeSound ) {
6061 configProvider . get ( CoreConstants . SETTINGS_NOTIFICATION_SOUND , true ) . then ( ( enabled ) => {
6162 this . notificationSound = ! ! enabled ;
Original file line number Diff line number Diff line change @@ -246,7 +246,15 @@ export class CorePushNotificationsProvider {
246246 * @return {Promise<PushOptions> } Promise with the push options resolved when done.
247247 */
248248 protected getOptions ( ) : Promise < PushOptions > {
249- return this . configProvider . get ( CoreConstants . SETTINGS_NOTIFICATION_SOUND , true ) . then ( ( soundEnabled ) => {
249+ let promise ;
250+
251+ if ( this . localNotificationsProvider . canDisableSound ( ) ) {
252+ promise = this . configProvider . get ( CoreConstants . SETTINGS_NOTIFICATION_SOUND , true ) ;
253+ } else {
254+ promise = Promise . resolve ( true ) ;
255+ }
256+
257+ return promise . then ( ( soundEnabled ) => {
250258 return {
251259 android : {
252260 sound : ! ! soundEnabled ,
Original file line number Diff line number Diff line change @@ -205,6 +205,17 @@ export class CoreLocalNotificationsProvider {
205205 } ) ;
206206 }
207207
208+ /**
209+ * Check whether sound can be disabled for notifications.
210+ *
211+ * @return {boolean } Whether sound can be disabled for notifications.
212+ */
213+ canDisableSound ( ) : boolean {
214+ // Only allow disabling sound in Android 7 or lower. In iOS and Android 8+ it can easily be done with system settings.
215+ return this . isAvailable ( ) && ! this . appProvider . isDesktop ( ) && this . platform . is ( 'android' ) &&
216+ this . platform . version ( ) . major < 8 ;
217+ }
218+
208219 /**
209220 * Create the default channel. It is used to change the name.
210221 *
@@ -577,7 +588,15 @@ export class CoreLocalNotificationsProvider {
577588 return this . localNotifications . cancel ( notification . id ) . finally ( ( ) => {
578589 if ( ! triggered ) {
579590 // Check if sound is enabled for notifications.
580- return this . configProvider . get ( CoreConstants . SETTINGS_NOTIFICATION_SOUND , true ) . then ( ( soundEnabled ) => {
591+ let promise ;
592+
593+ if ( this . canDisableSound ( ) ) {
594+ promise = this . configProvider . get ( CoreConstants . SETTINGS_NOTIFICATION_SOUND , true ) ;
595+ } else {
596+ promise = Promise . resolve ( true ) ;
597+ }
598+
599+ return promise . then ( ( soundEnabled ) => {
581600 if ( ! soundEnabled ) {
582601 notification . sound = null ;
583602 } else {
You can’t perform that action at this time.
0 commit comments