diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java b/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java index 4d5896c007282fa4a836ab0bff8e8ceeb089daa2..9b2d0ef5c5f6d110160884c0c91bc718c75170de 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/DataManager.java @@ -5807,8 +5807,9 @@ public class DataManager { public void playDemoRingerSound(@NotNull String ringerSound) { mNynjaSoundManager.playSound(ringerSound, false, NynjaSoundManager.Stream.MUSIC); - mSettingNotifications.setRingerSound(ringerSound); - saveNotificationSettings(); + if (mNotificationHelper.ringerSoundChange(mSettingNotifications, ringerSound)) { + mPreferenceHelper.setSettingNotifications(mSettingNotifications); + } } public void playSound(@NotNull String fileName, boolean loop, @NotNull NynjaSoundManager.Stream stream) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java b/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java index 03626d70d237c2ccbc8bdbb1abfb044abd9a4356..e6b368ae55f35775c1e15870658805578693b5b3 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/FireBaseMessagingService.java @@ -1,5 +1,6 @@ package com.nynja.mobile.communicator.data; +import android.app.KeyguardManager; import android.app.Notification; import android.app.PendingIntent; import android.content.Context; @@ -107,7 +108,8 @@ public class FireBaseMessagingService extends FirebaseMessagingService { if(model == null) break; Timber.i(model.toString()); if (mDataManager.getSettingNotifications().isCallNotifications()) { - boolean isMainActivityIsActive = mDataManager.isMainActivityIsActive();//!mDataManager.isInBackground();// +// boolean isMainActivityIsActive = mDataManager.isMainActivityIsActive(); + boolean isMainActivityIsActive = !mDataManager.isInBackground(); if (!isMainActivityIsActive) { mDataManager.reconnectConference(); } @@ -260,19 +262,17 @@ public class FireBaseMessagingService extends FirebaseMessagingService { public void sendCallPush(Context context, boolean isMainActivityIsActive, boolean hasActiveCall ) { Timber.i("Push.CALLING: sendCallPush() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); - Timber.i("Push.CALLING: sendCallPush(): check XX1"); String from = mDataManager.getConferenceSDK().getActiveConference().getCallerName(); String callId = mDataManager.getConferenceSDK().getActiveConference().mConference.callId(); - boolean isInBackground = mDataManager.isInBackground(); - Notification notification = mNotificationHelper.createCallPushNotification(context, from, callId, - isMainActivityIsActive || isInBackground, + boolean isDeviceLocked = mNotificationHelper.isDeviceLocked(); + Timber.i("Push.CALLING: sendCallPush(): check XX2" + + "; hasActiveCall=" + (hasActiveCall ? "true" : "false") + + "; isDeviceLocked=" + (isDeviceLocked ? "true" : "false")); + if (context instanceof FireBaseMessagingService) { + mNotificationHelper.createCallPushNotification(context, from, callId, + !hasActiveCall, mDataManager.getSettingNotifications(), true); - Timber.i("Push.CALLING: sendCallPush(): check XX2" + - "; hasActiveCall=" + (hasActiveCall?"true": "false")); - if (notification != null && !hasActiveCall && context instanceof FireBaseMessagingService) { - Timber.i("Push.CALLING: sendCallPush(): check XX3"); - ((FireBaseMessagingService)context).startForeground(ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID, notification); } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt b/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt index f43071d2e7bb46a68da6171353a572adf648bbea..31437a93cfcf5cc45a11e7defb351f8daf072b2b 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/audio/NynjaSoundManager.kt @@ -292,12 +292,12 @@ class NynjaSoundManager(context: Context) { mContext.contentResolver.registerContentObserver( android.provider.Settings.System.CONTENT_URI, true, - mContentObserver) + mContentObserver as RingerVolumeContentObserver) } private fun unregisterRingerVolumeContentObserver() { if (mContentObserver != null) { - mContext.contentResolver.unregisterContentObserver(mContentObserver) + mContext.contentResolver.unregisterContentObserver(mContentObserver!!) mContentObserver = null } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java b/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java index 88e72ee8c2ddfd48b74a2252f2da49a4b7ead952..fc0218451e0c2e5e4d6474eb5c67bc58b8edde2c 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/db/PreferenceHelper.java @@ -52,6 +52,7 @@ public class PreferenceHelper { private final static String NOTIFICATION_RINGER_SOUND = "notification ringer sound"; private final static String NOTIFICATION_CALL_NOTIFICATION = "notification_call_notifications"; private final static String NOTIFICATION_SOUND = "notification_sound"; + private final static String NOTIFICATION_RINGER_SOUND_INDEX = "notification_sound_index"; private final static String NOTIFICATION_ALERT_SOUND = "notification_alert_sound"; private final static String NOTIFICATION_IN_APP_VIBRATE = "notification_in_app_vibrate"; private final static String NOTIFICATION_SENT_MESSAGE_SOUND = "notification_sent_message_sound"; @@ -86,6 +87,8 @@ public class PreferenceHelper { private SharedPreferences mSharedPreferences; @Nullable private KeystoreTool mKeystoreTool; + private SettingNotifications mSettingNotifications; + @Inject public PreferenceHelper(@ApplicationContext Context context, @Nullable KeystoreTool keystoreTool) { //// TODO: 07.07.17 make secure @@ -169,9 +172,12 @@ public class PreferenceHelper { mSharedPreferences.edit().putString(NOTIFICATION_DEFAULT_SOUND, sn.getDefaultNotificationSound()).apply(); mSharedPreferences.edit().putLong(NOTIFICATION_PREFERENCE_VERSION, sn.getVersion()).apply(); mSharedPreferences.edit().putBoolean(NOTIFICATION_APP_ICON_BADGES_CLEARED, sn.isBadgesCleared()).apply(); + mSharedPreferences.edit().putLong(NOTIFICATION_RINGER_SOUND_INDEX, sn.getRingerSoundIndex()).apply(); } public SettingNotifications getSettingNotifications() { + if (mSettingNotifications != null) return mSettingNotifications; + boolean inAppVibrate = mSharedPreferences.getBoolean(NOTIFICATION_IN_APP_VIBRATE, true); String alertSound = mSharedPreferences.getString(NOTIFICATION_ALERT_SOUND, null); boolean sound = mSharedPreferences.getBoolean(NOTIFICATION_SOUND, true); @@ -184,13 +190,14 @@ public class PreferenceHelper { String defaultNotificationSound = mSharedPreferences.getString(NOTIFICATION_DEFAULT_SOUND, Consts.NotificationSounds.NYNJA.getDisplayName()); Long version = mSharedPreferences.getLong(NOTIFICATION_PREFERENCE_VERSION, 0L); boolean isBadgesCleared = mSharedPreferences.getBoolean(NOTIFICATION_APP_ICON_BADGES_CLEARED, false); - SettingNotifications ntfnsSettings = new SettingNotifications(newMessgeAlerts, callNotification, sound, alertSound, + Long ringerSoundIndex = mSharedPreferences.getLong(NOTIFICATION_PREFERENCE_VERSION, 0L); + mSettingNotifications = new SettingNotifications(newMessgeAlerts, callNotification, sound, alertSound, inAppVibrate, isMutedDuringCall, isIncomingSoundInMutedChat, ringerSound, isSentMessageSound, defaultNotificationSound, - isBadgesCleared); - ntfnsSettings.setVersion(version); + isBadgesCleared, ringerSoundIndex); + mSettingNotifications.setVersion(version); - return ntfnsSettings; + return mSettingNotifications; } public void setSettingsGeneral(SettingsGeneral sg) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt b/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt index ff203c23b686aa75f5c6200763981b09fa037ce3..8333e5aa82770a1ac0ab9c34382373f2f265b0a9 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/models/SettingNotifications.kt @@ -16,7 +16,8 @@ class SettingNotifications (var isNewMessageAlerts: Boolean, var ringerSound: String?, var isSentMessageSound: Boolean, var defaultNotificationSound: String?, - var isBadgesCleared: Boolean) { + var isBadgesCleared: Boolean, + var ringerSoundIndex: Long) { private var version: Long = 0L diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt index d3c2aa40e20633bc87fdb3ee887d81c227f7bdb3..bcba0112862d18b86d8aead0f044f6f8a7b5d4c7 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt @@ -868,8 +868,6 @@ class MainActivityPresenter : ConferenceSDKPresenter() { fun navigateToIncommingCall() { if (!mDataManager.getConferenceSDK().isConferenceActive()) return - if (mDataManager.conferenceSDK.startIncommingConferenceActivity(true, - null, NynjaNavigator.INCOMMING_CALL)) return; mRouter.navigateTo(NynjaNavigator.INCOMMING_CALL) } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt index 6434145bfcb654122ec34b61e99c1fe66d50641e..41003eb4563b7685581a8fd63a40492dd2fd6d25 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/NotificationChannelsPresenter.kt @@ -43,7 +43,8 @@ class NotificationChannelsPresenter : BasePresenter() } fun navigateToConferenceChannelSettings() { - openChannelSettings(Push.getChannelId(Push.CONFERENCE_V_01)) + openChannelSettings(Push.getChannelId(Push.CONFERENCE_V_01) + + mDataManager.settingNotifications.ringerSoundIndex) } fun openChannelSettings(channel: String) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/base/BaseActivity.java b/app/src/main/java/com/nynja/mobile/communicator/ui/base/BaseActivity.java index 20f9a06d769a7d014cb23b0826a2b7f5edd585b9..7c1509748aadc80876ab8bf7807ff4259e1777d8 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/base/BaseActivity.java +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/base/BaseActivity.java @@ -1,6 +1,7 @@ package com.nynja.mobile.communicator.ui.base; import android.Manifest; +import android.app.KeyguardManager; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; @@ -119,6 +120,12 @@ public abstract class BaseActivity extends MvpAppCompatActivity implements BaseA } protected void wakeLockActivityIfNeeds() { + if ((this instanceof MainActivity || + this instanceof IncomeCallActivity || + this instanceof CallActivity ) && + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setTurnScreenOn(true); + } } protected void requestPermissions() { diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java b/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java index 8dc5ca8301d53dedbd0225f4114024480a846709..8e208eef6ca97aec58df2b56077db59d195e56bc 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/Consts.java @@ -69,6 +69,53 @@ public interface Consts { } } + + public enum NotificationRingingSounds { + SUNRUSE("sunrise", R.raw.sunrise), + AQUA("aqua", R.raw.aqua), + CHEERFUL("cheerful", R.raw.cheerful), + DISCREET("discreet", R.raw.discreet), + IMPORTAN_STUFF("important_stuff", R.raw.important_stuff), + NYNJA("nynja", R.raw.nynja_ringing), + OPTIMISTIC("optimistic", R.raw.optimistic); + + private String name; + private int id; + + NotificationRingingSounds(String name, int id) { + this.name = name; + this.id = id; + } + + public String getName() { + return this.name; + } + + public int getId() { + return this.id; + } + + public static int getIdByName(String name) { + if (SUNRUSE.name.contentEquals(name)) { + return SUNRUSE.id; + } else if (AQUA.name.contentEquals(name)) { + return AQUA.id; + } else if (CHEERFUL.name.contentEquals(name)) { + return CHEERFUL.id; + } else if (DISCREET.name.contentEquals(name)) { + return DISCREET.id; + } else if (IMPORTAN_STUFF.name.contentEquals(name)) { + return IMPORTAN_STUFF.id; + } else if (NYNJA.name.contentEquals(name)) { + return NYNJA.id; + } else if (OPTIMISTIC.name.contentEquals(name)) { + return OPTIMISTIC.id; + } + return R.raw.nynja_ringing; + } + + } + String RINGER_SOUND_DEFAULT = RINGER_SOUND_FOLDER_NAME + "/nynja.mp3"; String MEMBER_ROOM_NAME_DELIMITER = " @ "; String URL_SCHEME_WS = "ws"; diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java b/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java index d06e1380c0da02101cc47824a9b09e9fd8225b39..f2b0e2d2a7d23156868d8ac6083fc8fdcaa0df69 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/FileUtils.java @@ -851,5 +851,20 @@ public class FileUtils { return name; } + @NonNull public static String getFileName(String fullPath) { + final int lastIndexOf = fullPath.lastIndexOf('/'); + return lastIndexOf > 0 ? fullPath.substring(lastIndexOf+1) : fullPath; + } + + @NonNull public static String getFileNameWithoutExt(String fullPath) { + final int lastIndexOf = fullPath.lastIndexOf('/'); + String name = lastIndexOf > 0 ? fullPath.substring(lastIndexOf+1) : fullPath;; + int pos = name.lastIndexOf("."); + if (pos > 0) { + name = name.substring(0, pos); + } + return name; + } + } diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java b/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java index 2d7f33a946f28d6295bf8c09cb5fafcd9ba9e959..4a258b57111148fa5d2755e52171283832a7737a 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/NotificationHelper.java @@ -1,10 +1,12 @@ package com.nynja.mobile.communicator.utils; import android.annotation.TargetApi; +import android.app.KeyguardManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; +import android.content.ContentResolver; import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; @@ -13,6 +15,7 @@ import android.media.AudioAttributes; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.PowerManager; import android.service.notification.StatusBarNotification; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; @@ -36,6 +39,8 @@ import com.nynja.mobile.communicator.injection.ApplicationContext; import com.nynja.mobile.communicator.ui.activities.MainActivity; import com.nynja.mobile.communicator.utils.container.data.model.Sticker; +import org.jetbrains.annotations.NotNull; + import javax.inject.Inject; import javax.inject.Singleton; @@ -74,65 +79,78 @@ public class NotificationHelper extends ContextWrapper { public void setupNotifications(SettingNotifications settingNotifications, boolean force) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; if (force) { - deleteChannelsIfExist(); + deleteChannelsIfExist(settingNotifications); } else if (settingNotifications.isLatestVersion()) { return; } - initChannels(settingNotifications.isSound(), - settingNotifications.isInAppVibrate(), - settingNotifications.getAlertSound()); + initChannels(settingNotifications); } - private void initChannels(boolean isSoundEnabled, boolean isVibrationEnabled, String alertSound) { + private void initChannels(SettingNotifications settingNotifications) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; - deleteChannelsIfExist(); + deleteChannelsIfExist(settingNotifications); + + boolean isSoundEnabled = settingNotifications.isSound(); + boolean isVibrationEnabled = settingNotifications.isInAppVibrate(); + String alertSound = settingNotifications.getAlertSound(); NotificationChannel channel = buildChannel(Push.getChannelId(Push.DEFAULT_V_01), - NOTIFICATION_CHANNEL_DEFAULT, "Default channel", isSoundEnabled, isVibrationEnabled, alertSound); + NOTIFICATION_CHANNEL_DEFAULT, "Default channel", + isSoundEnabled, isVibrationEnabled, + null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); channel = buildChannel(Push.getChannelId(Push.MESSAGE_V_01), - NOTIFICATION_CHANNEL_MESSAGE, "Message channel", isSoundEnabled, isVibrationEnabled, alertSound); + NOTIFICATION_CHANNEL_MESSAGE, "Message channel", + isSoundEnabled, isVibrationEnabled, + null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); channel = buildChannel(Push.getChannelId(Push.FRIEND_V_01), - NOTIFICATION_CHANNEL_FRIEND, "Friend channel", isSoundEnabled, isVibrationEnabled, alertSound); + NOTIFICATION_CHANNEL_FRIEND, "Friend channel", + isSoundEnabled, isVibrationEnabled, + null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); channel = buildChannel(Push.getChannelId(Push.REQUEST_FRIEND_V_01), - NOTIFICATION_CHANNEL_REQUEST, "Request channel", isSoundEnabled, isVibrationEnabled, alertSound); + NOTIFICATION_CHANNEL_REQUEST, "Request channel", + isSoundEnabled, isVibrationEnabled, + null); channel.setShowBadge(true); getManager().createNotificationChannel(channel); - channel = buildChannel(Push.getChannelId(Push.CONFERENCE_V_01), - NOTIFICATION_CHANNEL_CONFERENCE, "Conference channel", isSoundEnabled, isVibrationEnabled, alertSound); - channel.setShowBadge(false); - getManager().createNotificationChannel(channel); + buildRingingChannel(settingNotifications); channel = buildChannel(Push.CALLING, - NOTIFICATION_CHANNEL_CALLING, "Calling channel", false, false, null); + NOTIFICATION_CHANNEL_CALLING, "Calling channel", + false, false, + null); channel.setImportance(NotificationManager.IMPORTANCE_LOW); channel.setShowBadge(false); getManager().createNotificationChannel(channel); channel = buildChannel(Push.getChannelId(Push.UPLOADING), - NOTIFICATION_CHANNEL_UPLOADING, "Uploding", false, false, null); + NOTIFICATION_CHANNEL_UPLOADING, "Uploding", + false, false, + null); channel.setShowBadge(false); getManager().createNotificationChannel(channel); channel = buildChannel(Push.getChannelId(Push.DOWNLOADING), - NOTIFICATION_CHANNEL_DOWNLOADING, "Downloading", false, false, null); + NOTIFICATION_CHANNEL_DOWNLOADING, "Downloading", + false, false, + null); channel.setShowBadge(false); getManager().createNotificationChannel(channel); } @TargetApi(Build.VERSION_CODES.O) // delete the old channels with the old configurations to replace them with new ones - private void deleteChannelsIfExist() { + private void deleteChannelsIfExist(SettingNotifications settingNotifications) { // old channel versions ... getManager().deleteNotificationChannel(Push.DEFAULT); getManager().deleteNotificationChannel(Push.MESSAGE); @@ -160,26 +178,41 @@ public class NotificationHelper extends ContextWrapper { getManager().deleteNotificationChannel(Push.getChannelId(Push.UPLOADING)); getManager().deleteNotificationChannel(Push.getChannelId(Push.DOWNLOADING)); + // delete current ringing sound channel + deleteRingingChannel(settingNotifications); } + @TargetApi(Build.VERSION_CODES.O) @NonNull private NotificationChannel buildChannel(String name, String groupName, String desc, boolean isSoundEnabled, boolean isVibrationEnabled, String alertSound) { - NotificationChannel channel; // passing not valid raw res id to prom the system to set no sound and not affect the priority of the notification // and to set the label of the system sound item to app provided sound // we play the sound via MediaPlayer - Uri alarmSound = Uri.parse("android.resource://" + getPackageName() + "/" + "not valid raw id"); - channel = new NotificationChannel(name, + String sound = "not valid raw id"; + if (StringUtils.isNotEmpty(alertSound)) { + sound = alertSound; + } + Uri alarmSound = Uri.parse("android.resource://" + getPackageName() + "/" + sound); + + return buildChannelInternal(name, groupName, desc, isSoundEnabled, isVibrationEnabled, alarmSound); + } + + @TargetApi(Build.VERSION_CODES.O) + @NonNull + private NotificationChannel buildChannelInternal(String name, String groupName, String desc, + boolean isSoundEnabled, boolean isVibrationEnabled, + @NonNull Uri alarmSound) { + NotificationChannel channel = new NotificationChannel(name, groupName, isSoundEnabled ? NotificationManager.IMPORTANCE_HIGH : NotificationManager.IMPORTANCE_LOW); channel.setDescription(desc); channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); AudioAttributes.Builder builder = new AudioAttributes.Builder(); - builder.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION); +// builder.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION); builder.setUsage(AudioAttributes.USAGE_NOTIFICATION); channel.setSound(alarmSound, builder.build()); channel.enableVibration(isVibrationEnabled); @@ -189,6 +222,43 @@ public class NotificationHelper extends ContextWrapper { return channel; } + public synchronized boolean ringerSoundChange(SettingNotifications settingNotifications, @NotNull String ringerSound) { + String rSound = settingNotifications.getRingerSound(); + if (!StringUtils.isEqual(ringerSound, rSound)) { + deleteRingingChannel(settingNotifications); + settingNotifications.setRingerSound(ringerSound); + settingNotifications.setRingerSoundIndex(settingNotifications.getRingerSoundIndex() + 1); + buildRingingChannel(settingNotifications); + return true; + } + return false; + } + + @NonNull + private String getdRingingChannelId(SettingNotifications settingNotifications) { + return Push.getChannelId(Push.CONFERENCE_V_01)+settingNotifications.getRingerSoundIndex(); + } + + @TargetApi(Build.VERSION_CODES.O) + @NonNull + private void buildRingingChannel(SettingNotifications settingNotifications) { + String id = getdRingingChannelId(settingNotifications); + String groupName = NOTIFICATION_CHANNEL_CONFERENCE; + String desc = "Conference channel"; + Uri notificationSoundUri = getCallNotificationSoundUri(settingNotifications.getRingerSound()); + NotificationChannel channel = buildChannelInternal(id, groupName, desc, + settingNotifications.isSound(), settingNotifications.isInAppVibrate(), + notificationSoundUri); + channel.setShowBadge(false); + getManager().createNotificationChannel(channel); + } + + @TargetApi(Build.VERSION_CODES.O) + private void deleteRingingChannel(SettingNotifications settingNotifications) { + String id = getdRingingChannelId(settingNotifications); + getManager().deleteNotificationChannel(id); + } + private NotificationManager getManager() { if (mManager == null) { mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); @@ -203,28 +273,40 @@ public class NotificationHelper extends ContextWrapper { PendingIntent rejectPendingIntent, boolean isMainActivityIsActive, SettingNotifications settingNotifications) { - Uri notificationSoundUri = getNotificationSoundUri(settingNotifications.getDefaultNotificationSound()); + Uri notificationSoundUri = getCallNotificationSoundUri(settingNotifications.getRingerSound()); Timber.i("Push.CALLING: createCallPushNotification(): check XXX1"); - Notification notification = buildCallNotification(intent, answerPendingIntent, rejectPendingIntent, - settingNotifications, from, isMainActivityIsActive, notificationSoundUri); + Notification notification = buildCallNotification(context, intent, + answerPendingIntent, rejectPendingIntent, + settingNotifications, from, notificationSoundUri); if (isMainActivityIsActive) { Timber.i("Push.CALLING: createCallPushNotification(): check XXX2"); -// clearCallPush(ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); -// Timber.i("Push.CALLING: createCallPushNotification(): check XXX3"); - sendRingingNotify(context, notification, ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID, - settingNotifications); - Timber.i("Push.CALLING: createCallPushNotification(): check XXX4"); + sendRingingNotify(notification, ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); + Timber.i("Push.CALLING: createCallPushNotification(): check XXX3"); return null; } return notification; } + public boolean isDeviceLocked() { + KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); + if (keyguardManager != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + return keyguardManager.isDeviceLocked(); + } + } + return false; + } + public synchronized Notification createCallPushNotification(Context context, String from, String callId, boolean isMainActivityIsActive, SettingNotifications settingNotifications, boolean isPush) { - Timber.i((isPush?"Push.CALLING": "Grpc.CALLING")+"Push.CALLING: createCallPushNotification() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); + Timber.i((isPush?"Push.CALLING": "Grpc.CALLING")+": createCallPushNotification() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); + if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) { + Timber.i((isPush?"Push.CALLING": "Grpc.CALLING")+": createCallPushNotification() Notifications are not enabledby the System !!!"); + return null; + } Intent fullScreenIntent = MainActivity.getLaunchIntent(context, false, true); fullScreenIntent.putExtra(MainActivity.INTENT_FROM_CALL_NOTIFICATION, true); fullScreenIntent.putExtra(MainActivity.INTENT_NOTIFICATION_CALL_ID, callId); @@ -404,18 +486,29 @@ public class NotificationHelper extends ContextWrapper { } @NonNull - public Notification buildCallNotification(Intent fullScreenIntent, + public synchronized Notification buildCallNotification(Context context, + Intent fullScreenIntent, PendingIntent answerPendingIntent, PendingIntent rejectPendingIntent, SettingNotifications settingNotifications, String from, - boolean isMainActivityIsActive, Uri notificationSoundUri) { - String type = handleChannelIdToLatestOne(Push.CONFERENCE); + String type = getdRingingChannelId(settingNotifications); + boolean notificationsEnabled = areNotificationsEnabled(context, getManager(), type); + if (!notificationsEnabled) { + Timber.w("buildCallNotification(): 'Calls' Notifications are DISABLED!!!!"); + return null; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = getManager().getNotificationChannel(type); + if (channel == null) { + buildRingingChannel(settingNotifications); + } + } int iconRes = (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) ? R.mipmap.ic_launcher : R.drawable.ic_notification; PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, - fullScreenIntent, 0);// | PendingIntent.FLAG_CANCEL_CURRENT); + fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT); String contentText = getString(R.string.call_notification_incoming_from, from); Bundle args = new Bundle(); args.putInt(MainActivity.INTENT_CALL_NOTIFICATION_ID, ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); @@ -468,10 +561,15 @@ public class NotificationHelper extends ContextWrapper { notification.defaults |= Notification.DEFAULT_VIBRATE; } } else { - notification.sound = null; - notification.defaults = 0; - notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_NO_CLEAR); - notification.defaults &= Notification.DEFAULT_VIBRATE; + if (settingNotifications.isSound() && mNynjaSoundManager.canPlayRingingSound()) { + notification.sound = notificationSoundUri; + notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR); + } else { + notification.sound = null; + notification.defaults = 0; + notification.flags |= (Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_NO_CLEAR); + notification.defaults &= Notification.DEFAULT_VIBRATE; + } } notification.ledARGB = Color.RED; notification.ledOnMS = 300; @@ -499,38 +597,22 @@ public class NotificationHelper extends ContextWrapper { } } - public void sendRingingNotify(Context context, - Notification notification, - int id, - SettingNotifications settingNotifications) { - boolean playSound = false; + public void sendRingingNotify( Notification notification, int id) { + NotificationManager notificationManager = getManager(); + if (notification == null) { + Timber.w("Push.CALLING: sendRingingNotify(): notification.is NULL!!!"); + return; + } + if (notificationManager == null) { + Timber.w("Push.CALLING: sendRingingNotify(): NotificationManager.is NULL!!!"); + return; + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - Timber.i("Push.CALLING: sendRingingNotify(): check 1"); - NotificationManager notificationManager = getManager(); - if (notificationManager != null) { - boolean isSoundEnabled = settingNotifications.isIncomingSoundInMutedChat(); - mNynjaSoundManager.updateShouldPlayRingingSound(isSoundEnabled, - settingNotifications.isInAppVibrate(), false); - Timber.i("Push.CALLING: sendRingingNotify(): mNynjaSoundManager.canPlayRingingSound="+(mNynjaSoundManager.canPlayRingingSound()? "true":"false")); - playSound = (areNotificationsEnabled(context, notificationManager, handleChannelIdToLatestOne(Push.CONFERENCE)) - // && settingNotifications.isSound() - && mNynjaSoundManager.canPlayRingingSound() - ); - notificationManager.notify(getString(R.string.app_name), id, notification); - } + Timber.i("Push.CALLING: sendRingingNotify(): mNynjaSoundManager.canPlayRingingSound="+(mNynjaSoundManager.canPlayRingingSound()? "true":"false")); + notificationManager.notify(getString(R.string.app_name), id, notification); } else { Timber.i("Push.CALLING: sendRingingNotify(): check 2"); - NotificationManager notificationManager = getManager(); - if (notificationManager != null) { - playSound = (areNotificationsEnabled(context, notificationManager, handleChannelIdToLatestOne(Push.CONFERENCE))); - notificationManager.notify(id, notification); - } - } - Timber.i("Push.CALLING: sendRingingNotify(): playSound="+(playSound? "true":"false")); - if (playSound) { - Timber.i("Push.CALLING: sendRingingNotify(): check XXXX1"); - mNynjaSoundManager.playCallRinging(settingNotifications.getRingerSound(), false); - Timber.i("Push.CALLING: sendRingingNotify(): check XXXX2"); + notificationManager.notify(id, notification); } } @@ -623,26 +705,32 @@ public class NotificationHelper extends ContextWrapper { return Uri.parse(path); } - private Uri getCallNotificationSoundUri(Context context, String soundName) { + private String getCallNotificationSoundName( String soundName) { soundName = soundName == null ? "" : soundName; if (Consts.NOTIFICATION_SOUND_NO_SOUND.equalsIgnoreCase(soundName)) { return null; } - String basePath = context.getResources().getAssets().toString() + "/"; - if (soundName.isEmpty()) { - soundName = Consts.NotificationSounds.NYNJA.getDisplayName(); - } - String path = basePath + soundName; + String basePath = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/"; + String name = FileUtils.getFileNameWithoutExt(soundName); + String path = basePath + Consts.NotificationRingingSounds.getIdByName(name); if (path == null) { - path = basePath + R.raw.nynja; + path = basePath + R.raw.nynja_ringing; } - return Uri.parse(path); + return path; + } + + public Uri getCallNotificationSoundUri( String soundName) { + return Uri.parse(getCallNotificationSoundName(soundName)); } public boolean areNotificationsEnabled(Context context, NotificationManager manager, String channelId) { Timber.i("Push.CALLING: areNotificationsEnabled(): check 1"); + if (manager == null) { + Timber.i("Push.CALLING: areNotificationsEnabled(): NotificationManager is null!!!"); + return false; + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (!manager.areNotificationsEnabled()) { Timber.i("Push.CALLING: areNotificationsEnabled(): check 2"); @@ -654,13 +742,14 @@ public class NotificationHelper extends ContextWrapper { if (channel != null) { Timber.i("Push.CALLING: areNotificationsEnabled(): check 4"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - Timber.i("Push.CALLING: areNotificationsEnabled(): check 5"); - return channel.getImportance() == NotificationManager.IMPORTANCE_HIGH; + Timber.i("Push.CALLING: areNotificationsEnabled(): Importance=" + channel.getImportance()); + //return channel.getImportance() >= NotificationManager.IMPORTANCE_HIGH; } else { Timber.i("Push.CALLING: areNotificationsEnabled(): check 6"); - return channel.getImportance() != NotificationManager.IMPORTANCE_NONE; } + return channel.getImportance() != NotificationManager.IMPORTANCE_NONE; } + return true; } return false; } else { diff --git a/app/src/main/res/raw/aqua.mp3 b/app/src/main/res/raw/aqua.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..eade4b71712e5a37d8495678573152f2c9a66fe0 Binary files /dev/null and b/app/src/main/res/raw/aqua.mp3 differ diff --git a/app/src/main/res/raw/cheerful.mp3 b/app/src/main/res/raw/cheerful.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..c9a66e24ceb6035638e2064c17de269f6166e206 Binary files /dev/null and b/app/src/main/res/raw/cheerful.mp3 differ diff --git a/app/src/main/res/raw/discreet.mp3 b/app/src/main/res/raw/discreet.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..9900d9b96539d026a5429312304a5417c701b161 Binary files /dev/null and b/app/src/main/res/raw/discreet.mp3 differ diff --git a/app/src/main/res/raw/important_stuff.mp3 b/app/src/main/res/raw/important_stuff.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..0db04b3ecf3f1b24429234a41fb39f1e5d0419e2 Binary files /dev/null and b/app/src/main/res/raw/important_stuff.mp3 differ diff --git a/app/src/main/res/raw/nynja_ringing.mp3 b/app/src/main/res/raw/nynja_ringing.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..de5759baa950b38d87a9986a6bdf74336f62faef Binary files /dev/null and b/app/src/main/res/raw/nynja_ringing.mp3 differ diff --git a/app/src/main/res/raw/optimistic.mp3 b/app/src/main/res/raw/optimistic.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..f0d434ce223d79dbfd8be731348cfce8cf509a28 Binary files /dev/null and b/app/src/main/res/raw/optimistic.mp3 differ diff --git a/app/src/main/res/raw/sunrise.mp3 b/app/src/main/res/raw/sunrise.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..6e6baf0acf6175adbc79971be84bc5a56fee372e Binary files /dev/null and b/app/src/main/res/raw/sunrise.mp3 differ