MOBILE-3039 core: Don't allow disable sound in iOS and Android 8+

main
Dani Palou 2019-06-06 09:44:05 +02:00
parent 3a56fa0e80
commit ed35e57e1c
3 changed files with 31 additions and 3 deletions

View File

@ -55,7 +55,8 @@ export class AddonNotificationsSettingsPage implements OnDestroy {
@Optional() private svComponent: CoreSplitViewComponent) {
this.notifPrefsEnabled = notificationsProvider.isNotificationPreferencesEnabled();
this.canChangeSound = localNotificationsProvider.isAvailable() && !appProvider.isDesktop();
this.canChangeSound = localNotificationsProvider.canDisableSound();
if (this.canChangeSound) {
configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((enabled) => {
this.notificationSound = !!enabled;

View File

@ -246,7 +246,15 @@ export class CorePushNotificationsProvider {
* @return {Promise<PushOptions>} Promise with the push options resolved when done.
*/
protected getOptions(): Promise<PushOptions> {
return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => {
let promise;
if (this.localNotificationsProvider.canDisableSound()) {
promise = this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true);
} else {
promise = Promise.resolve(true);
}
return promise.then((soundEnabled) => {
return {
android: {
sound: !!soundEnabled,

View File

@ -205,6 +205,17 @@ export class CoreLocalNotificationsProvider {
});
}
/**
* Check whether sound can be disabled for notifications.
*
* @return {boolean} Whether sound can be disabled for notifications.
*/
canDisableSound(): boolean {
// Only allow disabling sound in Android 7 or lower. In iOS and Android 8+ it can easily be done with system settings.
return this.isAvailable() && !this.appProvider.isDesktop() && this.platform.is('android') &&
this.platform.version().major < 8;
}
/**
* Create the default channel. It is used to change the name.
*
@ -577,7 +588,15 @@ export class CoreLocalNotificationsProvider {
return this.localNotifications.cancel(notification.id).finally(() => {
if (!triggered) {
// Check if sound is enabled for notifications.
return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => {
let promise;
if (this.canDisableSound()) {
promise = this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true);
} else {
promise = Promise.resolve(true);
}
return promise.then((soundEnabled) => {
if (!soundEnabled) {
notification.sound = null;
} else {