From 588b9860054239f1100201b552a00830a485d22a Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 18 Dec 2018 17:01:55 +0100 Subject: [PATCH] reactivate socket voip, not used in push notification --- Classes/LinphoneManager.m | 40 ++++++++++++++++++++++++++++++++---- Resources/linphonerc | 2 +- Resources/linphonerc-factory | 1 + Resources/linphonerc~ipad | 2 +- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 8fab4a6f3..c28dff5ab 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -361,7 +361,7 @@ static int check_should_migrate_images(void *data, int argc, char **argv, char * NSDictionary *defaults = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; NSArray *defaults_keys = [defaults allKeys]; NSDictionary *values = - @{ @"backgroundmode_preference" : @YES, + @{ @"backgroundmode_preference" : @NO, @"debugenable_preference" : @NO, @"start_at_boot_preference" : @YES }; BOOL shouldSync = FALSE; @@ -758,8 +758,17 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char withCompletionHandler:^(NSError *_Nullable error) {if (error) LOGD(@"Error while adding notification request : %@", error.description);}]; } - linphone_core_set_network_reachable(LC, FALSE); - LinphoneManager.instance.connectivity = none; + LinphoneProxyConfig *proxyCfg = linphone_core_get_default_proxy_config(theLinphoneCore); + BOOL pushNotifEnabled = false; + // handle proxy config if any + if (proxyCfg) { + const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL; + pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0); + } + if (![LinphoneManager.instance lpConfigBoolForKey:@"backgroundmode_preference"] || pushNotifEnabled) { + linphone_core_set_network_reachable(LC, FALSE); + LinphoneManager.instance.connectivity = none; + } } LinphoneCallLog *callLog2 = linphone_call_get_call_log(call); const char *call_id2 = linphone_call_log_get_call_id(callLog2); @@ -2364,7 +2373,30 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } } - if ([LinphoneManager.instance lpConfigBoolForKey:@"backgroundmode_preference"]) { + if ([LinphoneManager.instance lpConfigBoolForKey:@"backgroundmode_preference"] && !pushNotifEnabled) { + // Keep this!! Socket VoIP is deprecated after 9.0, but sometimes it's the only way to keep the phone background and receive the call. For example, when there is only local area network. + // register keepalive + if ([[UIApplication sharedApplication] + setKeepAliveTimeout:600 /*(NSTimeInterval)linphone_proxy_config_get_expires(proxyCfg)*/ + handler:^{ + LOGW(@"keepalive handler"); + mLastKeepAliveDate = [NSDate date]; + if (theLinphoneCore == nil) { + LOGW(@"It seems that Linphone BG mode was deactivated, just skipping"); + return; + } + [_iapManager check]; + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { + // For registration register + [self refreshRegisters]; + } + linphone_core_iterate(theLinphoneCore); + }]) { + + LOGI(@"keepalive handler succesfully registered"); + } else { + LOGI(@"keepalive handler cannot be registered"); + } shouldEnterBgMode = TRUE; } } diff --git a/Resources/linphonerc b/Resources/linphonerc index e2861ccd8..65c31b407 100644 --- a/Resources/linphonerc +++ b/Resources/linphonerc @@ -1,7 +1,7 @@ [app] animations_preference=1 autoanswer_notif_preference=1 -backgroundmode_preference=1 +backgroundmode_preference=0 edge_opt_preference=0 enable_log_collect=0 file_transfer_migration_done=1 diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 6eefe6632..6316e5bcc 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -21,6 +21,7 @@ debug_popup_email=linphone-iphone@belledonne-communications.com send_logs_include_linphonerc_and_chathistory=0 #use_phone_number=0 publish_presence=0 +backgroundmode_preference=0 [assistant] password_length=-1 diff --git a/Resources/linphonerc~ipad b/Resources/linphonerc~ipad index 1eaec502d..54de79c3c 100644 --- a/Resources/linphonerc~ipad +++ b/Resources/linphonerc~ipad @@ -1,7 +1,7 @@ [app] animations_preference=1 autoanswer_notif_preference=1 -backgroundmode_preference=1 +backgroundmode_preference=0 edge_opt_preference=0 enable_log_collect=0 file_transfer_migration_done=1