From 765f449c94fc5d58a7379111c0a261362060336f Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 6 Apr 2021 17:27:39 +0200 Subject: [PATCH] use auto enterBackground and enterForeground --- Classes/LinphoneAppDelegate.m | 2 - Classes/LinphoneManager.h | 1 - Classes/LinphoneManager.m | 113 ---------------------------------- Resources/linphonerc-factory | 1 - 4 files changed, 117 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index ed15cb9fc..3b430148b 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -61,7 +61,6 @@ - (void)applicationDidEnterBackground:(UIApplication *)application { LOGI(@"%@", NSStringFromSelector(_cmd)); if (linphone_core_get_global_state(LC) != LinphoneGlobalOff) { - [LinphoneManager.instance enterBackgroundMode]; [LinphoneManager.instance.fastAddressBook clearFriends]; if (PhoneMainView.instance.currentView == ChatConversationView.compositeViewDescription) { ChatConversationView *view = VIEW(ChatConversationView); @@ -110,7 +109,6 @@ [PhoneMainView.instance startUp]; } LinphoneManager *instance = LinphoneManager.instance; - [instance becomeActive]; if (instance.fastAddressBook.needToUpdate) { //Update address book for external changes diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 43d7816d9..1a8538959 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -122,7 +122,6 @@ typedef struct _LinphoneManagerSounds { - (void)startLinphoneCore; - (BOOL)resignActive; - (void)becomeActive; -- (BOOL)enterBackgroundMode; - (void)addPushCallId:(NSString*) callid; - (void)configurePushTokenForProxyConfigs; - (void)configurePushTokenForProxyConfig: (LinphoneProxyConfig*)cfg; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a25e84330..b8b68cc44 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1208,11 +1208,6 @@ static BOOL libStarted = FALSE; [errView addAction:defaultAction]; [PhoneMainView.instance presentViewController:errView animated:YES completion:nil]; } - - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { - // go directly to bg mode - [self enterBackgroundMode]; - } } void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, const char *resp) { @@ -1490,111 +1485,14 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { return; } - if ([self lpConfigBoolForKey:@"publish_presence"]) { - // set present to "tv", because "available" does not work yet - if (enabled) { - linphone_core_set_presence_model(LC, linphone_core_create_presence_model_with_activity(LC, LinphonePresenceActivityTV, NULL)); - } - - const MSList *proxies = linphone_core_get_proxy_config_list(LC); - while (proxies) { - LinphoneProxyConfig *cfg = proxies->data; - linphone_proxy_config_edit(cfg); - linphone_proxy_config_enable_publish(cfg, enabled); - linphone_proxy_config_done(cfg); - proxies = proxies->next; - } - // force registration update first, then update friend list subscription - [self iterate]; - } - linphone_core_enable_friend_list_subscription(LC, enabled && [LinphoneManager.instance lpConfigBoolForKey:@"use_rls_presence"]); } -- (BOOL)enterBackgroundMode { - linphone_core_enter_background(LC); - - LinphoneProxyConfig *proxyCfg = linphone_core_get_default_proxy_config(theLinphoneCore); - BOOL shouldEnterBgMode = FALSE; - - // disable presence - [self enableProxyPublish:NO]; - - // handle proxy config if any - if (proxyCfg) { - BOOL pushNotifEnabled = linphone_proxy_config_is_push_notification_allowed(proxyCfg); - if ([LinphoneManager.instance lpConfigBoolForKey:@"backgroundmode_preference"] || pushNotifEnabled) { - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { - // For registration register - [self refreshRegisters]; - } - } - - if ([LinphoneManager.instance lpConfigBoolForKey:@"voip_mode_preference"] && [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; - } - } - - LinphoneCall *currentCall = linphone_core_get_current_call(theLinphoneCore); - const bctbx_list_t *callList = linphone_core_get_calls(theLinphoneCore); - if (!currentCall // no active call - && callList // at least one call in a non active state - && bctbx_list_find_custom(callList, (bctbx_compare_func)comp_call_state_paused, NULL)) { - [self startCallPausedLongRunningTask]; - } - if (callList) // If at least one call exist, enter normal bg mode - shouldEnterBgMode = TRUE; - - // Stop the video preview - if (theLinphoneCore) { - linphone_core_enable_video_preview(theLinphoneCore, FALSE); - [self iterate]; - } - linphone_core_stop_dtmf_stream(theLinphoneCore); - - LOGI(@"Entering [%s] bg mode", shouldEnterBgMode ? "normal" : "lite"); - if (!shouldEnterBgMode && floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { - BOOL pushNotifEnabled = linphone_proxy_config_is_push_notification_allowed(proxyCfg); - if (pushNotifEnabled) { - LOGI(@"Keeping lc core to handle push"); - return YES; - } - return NO; - } - return YES; -} - - (void)becomeActive { linphone_core_enter_foreground(LC); [self checkNewVersion]; - // enable presence - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { - [self refreshRegisters]; - } if (pausedCallBgTask) { [[UIApplication sharedApplication] endBackgroundTask:pausedCallBgTask]; pausedCallBgTask = 0; @@ -1605,7 +1503,6 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } /*IOS specific*/ - linphone_core_start_dtmf_stream(theLinphoneCore); [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted){ }]; @@ -1614,16 +1511,6 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { if (linphone_core_video_display_enabled(theLinphoneCore) && [self lpConfigBoolForKey:@"preview_preference"]) { linphone_core_enable_video_preview(theLinphoneCore, TRUE); } - /*check last keepalive handler date*/ - if (mLastKeepAliveDate != Nil) { - NSDate *current = [NSDate date]; - if ([current timeIntervalSinceDate:mLastKeepAliveDate] > 700) { - NSString *datestr = [mLastKeepAliveDate description]; - LOGW(@"keepalive handler was called for the last time at %@", datestr); - } - } - - [self enableProxyPublish:YES]; } - (void)refreshRegisters { diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 0299da623..82dab2e2a 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -20,7 +20,6 @@ show_remote_provisioning_in_assistant=0 debug_popup_email=linphone-iphone@belledonne-communications.com send_logs_include_linphonerc_and_chathistory=0 #use_phone_number=0 -publish_presence=0 backgroundmode_preference=1 use_rls_presence=1 use_callkit=1