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 48a6b942d100aa91d5cf9ed689392468610819e5..a44a52deda686a02f881fbe8d75ad94b3961ac6d 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 @@ -260,29 +260,29 @@ 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: handleConferencePushNotification(): handleCallPush XXX"); + 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, - isInBackground, //isMainActivityIsActive, + isMainActivityIsActive, mDataManager.getSettingNotifications()); - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXXX" + + Timber.i("Push.CALLING: sendCallPush(): check XX2" + "; hasActiveCall=" + (hasActiveCall?"true": "false")); - if (notification != null && !hasActiveCall && !isMainActivityIsActive - && context instanceof FireBaseMessagingService) { - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXXXX"); + 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); } } private synchronized void handleCallPush(byte[] decoded, boolean isMainActivityIsActive) { + Timber.i("Push.CALLING: handleCallPush() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); boolean hasActiveCall = mDataManager.getConferenceSDK().hasCreatedActiveCall(); boolean startActivity = !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q); boolean result = mDataManager.handleConferencePushNotification(decoded, isMainActivityIsActive, startActivity); boolean isCallRinging = mDataManager.getConferenceSDK().isCallRinging(); - Timber.i("Push.CALLING: handleConferencePushNotification()=" + (result?"true": "false") + "; isCallRinging="+ - (isCallRinging?"true": "false") + "; startActivity=" + (startActivity?"true": "false")); + Timber.i("Push.CALLING: handleCallPush()=" + (result?"true": "false") + "; isCallRinging="+ + (isCallRinging?"true": "false") + "; startActivity=" + (startActivity?"true": "false") + + "; hasActiveCall=" + (hasActiveCall?"true": "false")); if (result && !startActivity && isCallRinging && !hasActiveCall) { sendCallPush(this, isMainActivityIsActive, hasActiveCall); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java index 911f83e2883503cc2d04b095f9c4ddf0227257bc..2ff3079665ba9d7ddf944deddc964ce4b3a6611f 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java @@ -475,6 +475,7 @@ public class ConferenceSDKModule extends BaseSDKModule { if (iConference != null) { if (iConference.isRinging()) { if (result) { + Timber.i("ConferenceSDKModule::handlePushNotification(): check 1 "); createIncomingConference(iConference, false); mActiveConference.isRinging = true; } @@ -2780,8 +2781,11 @@ public class ConferenceSDKModule extends BaseSDKModule { public boolean startIncommingConferenceActivity(boolean delayed, String callId, String screenKey) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && callId != null) { + Timber.d("startIncommingConferenceActivity with \'ConferenceId\'=\'" + callId + + "; delayed=" + (delayed?"true": "false")); + final String name = mActiveConference.getCallerName(); new Handler(Looper.getMainLooper()).post(() -> { - mNotificationHelper.createCallPushNotification(getContext(), mActiveConference.getCallerName(), callId, true, + mNotificationHelper.createCallPushNotification(getContext(), name, callId, true, mSettingNotifications); }); return true; @@ -2916,6 +2920,8 @@ public class ConferenceSDKModule extends BaseSDKModule { if (!hasCreatedActiveCall()) return false; mActiveConference.mData.isOwnStreamActive = false; initConferenceCall(startActivity); + Timber.d("createIncomingCallAndStartRinging with \'ConferenceId\'=\'" + callId + + "; startActivity=" + (startActivity?"true": "false")); if (startActivity) { if (Consts.SHOW_INCOMING_CALLS_AS_POPUP_NOTIFICATIONS) { new Handler(Looper.getMainLooper()).post(() -> { @@ -2932,6 +2938,8 @@ public class ConferenceSDKModule extends BaseSDKModule { private synchronized boolean createIncomingConference(NYNCall iConference, boolean startActivity) { if (iConference == null) return false; if (iConference.isOutgoing()) return false; + Timber.d("createIncomingConference with \'ConferenceId\'=\'" + iConference.callId() + + "; startActivity=" + (startActivity?"true": "false")); boolean isCallAccess = mSettingNotifications.isCallNotifications() || mStateDevice.isDeviceActive(); if (!hasCreatedActiveCall() && iConference != null && isCallAccess) { return createIncomingCallAndStartRinging(iConference, false, startActivity); 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 47aa822853a8c9243630de4228ee72e669cbd485..f4a507b546afdfa59274416b009145705281047f 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 @@ -18,6 +18,7 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationManagerCompat; import com.nynja.mobile.communicator.R; import com.nynja.mobile.communicator.data.DescManager; @@ -195,37 +196,34 @@ public class NotificationHelper extends ContextWrapper { return mManager; } - public Notification createCallPushNotification(String from, + public Notification createCallPushNotification(Context context, + String from, Intent intent, PendingIntent answerPendingIntent, PendingIntent rejectPendingIntent, boolean isMainActivityIsActive, SettingNotifications settingNotifications) { Uri notificationSoundUri = getNotificationSoundUri(settingNotifications.getDefaultNotificationSound()); - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX1"); - - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX2"); + Timber.i("Push.CALLING: createCallPushNotification(): check XXX1"); + Notification notification = buildCallNotification(intent, answerPendingIntent, rejectPendingIntent, + settingNotifications, from, isMainActivityIsActive, notificationSoundUri); if (isMainActivityIsActive) { - Notification notification = buildCallNotification(intent, answerPendingIntent, rejectPendingIntent, - settingNotifications, from, isMainActivityIsActive, notificationSoundUri); - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX3"); + Timber.i("Push.CALLING: createCallPushNotification(): check XXX2"); // clearCallPush(ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); -// Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX4"); - sendRingingNotify(notification, 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: handleConferencePushNotification(): handleCallPush XXX5"); + Timber.i("Push.CALLING: createCallPushNotification(): check XXX4"); return null; } - return buildCallNotification(intent, answerPendingIntent, rejectPendingIntent, - settingNotifications, from, isMainActivityIsActive, notificationSoundUri); + return notification; } public synchronized Notification createCallPushNotification(Context context, String from, String callId, boolean isMainActivityIsActive, SettingNotifications settingNotifications) { - Timber.i("Push.CALLING: sendCallPush() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX"); + Timber.i("Push.CALLING: createCallPushNotification() isMainActivityIsActive=" + (isMainActivityIsActive?"true": "false")); Intent fullScreenIntent = MainActivity.getLaunchIntent(context, false, true); fullScreenIntent.putExtra(MainActivity.INTENT_FROM_CALL_NOTIFICATION, true); fullScreenIntent.putExtra(MainActivity.INTENT_NOTIFICATION_CALL_ID, callId); @@ -248,7 +246,8 @@ public class NotificationHelper extends ContextWrapper { context, 1, rejectIntent, PendingIntent.FLAG_UPDATE_CURRENT); - return createCallPushNotification(from, + return createCallPushNotification(context, + from, fullScreenIntent, answerPendingIntent, rejectPendingIntent, @@ -447,6 +446,7 @@ public class NotificationHelper extends ContextWrapper { notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true); + notificationBuilder.setPriority(NotificationManager.IMPORTANCE_HIGH); } else { notificationBuilder.setContentIntent(fullScreenPendingIntent); } @@ -497,22 +497,39 @@ public class NotificationHelper extends ContextWrapper { } } - public void sendRingingNotify(Notification notification, + public void sendRingingNotify(Context context, + Notification notification, int id, SettingNotifications settingNotifications) { - NotificationManager notificationManager = getManager(); - if (notificationManager != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + boolean playSound = false; + 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); - } else { - notificationManager.notify(id, notification); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX7"); - mNynjaSoundManager.playCallRinging(settingNotifications.getRingerSound(), false); - Timber.i("Push.CALLING: handleConferencePushNotification(): handleCallPush XXX8"); + } 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"); + } } public void clearPushMessageForChat(int notificationId) { @@ -603,4 +620,50 @@ public class NotificationHelper extends ContextWrapper { return Uri.parse(path); } + + private Uri getCallNotificationSoundUri(Context context, 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; + if (path == null) { + path = basePath + R.raw.nynja; + } + + return Uri.parse(path); + } + + public boolean areNotificationsEnabled(Context context, NotificationManager manager, String channelId) { + Timber.i("Push.CALLING: areNotificationsEnabled(): check 1"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (!manager.areNotificationsEnabled()) { + Timber.i("Push.CALLING: areNotificationsEnabled(): check 2"); + return false; + } + if(StringUtils.isNotEmpty(channelId)) { + Timber.i("Push.CALLING: areNotificationsEnabled(): check 3"); + NotificationChannel channel = manager.getNotificationChannel(channelId); + 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; + } else { + Timber.i("Push.CALLING: areNotificationsEnabled(): check 6"); + return channel.getImportance() != NotificationManager.IMPORTANCE_NONE; + } + } + } + return false; + } else { + Timber.i("Push.CALLING: areNotificationsEnabled(): check 7"); + return NotificationManagerCompat.from(context).areNotificationsEnabled(); + } + } }