From ba39301ffd0b742e9487f2bbbf339065eadea05e Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sun, 27 Apr 2014 14:49:48 +0200 Subject: [PATCH] fix start at boot (was broken) protect launching at boot with a background task and another background task in belle-sip to protect notifications of incoming messages and calls. --- Classes/LinphoneAppDelegate.h | 1 + Classes/LinphoneAppDelegate.m | 9 +++++++-- Classes/LinphoneCoreSettingsStore.m | 1 + Classes/LinphoneManager.m | 7 +++++-- submodules/belle-sip | 2 +- submodules/linphone | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index 6ab39badf..bc687d8dd 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -30,6 +30,7 @@ @interface LinphoneAppDelegate : NSObject { @private UIWindow *window; + UIBackgroundTaskIdentifier bgStartId; BOOL started; int savedMaxCall; } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index bd7a32af8..6a58710f8 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -134,18 +134,23 @@ // we've been woken up directly to background; if( !start_at_boot || !background_mode ) { // autoboot disabled or no background, and no push: do nothing and wait for a real launch + /*output a log with NSLog, because the ortp logging system isn't activated yet at this time*/ + NSLog(@"Linphone launch doing nothing because start_at_boot or background_mode are not activated.", NULL); return YES; } } - + bgStartId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + [LinphoneLogger log:LinphoneLoggerWarning format:@"Background task for application launching expired."]; + [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; + }]; [self startApplication]; NSDictionary *remoteNotif =[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (remoteNotif){ [LinphoneLogger log:LinphoneLoggerLog format:@"PushNotification from launch received."]; [self processRemoteNotification:remoteNotif]; } - + if (bgStartId!=UIBackgroundTaskInvalid) [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; [[PhoneMainView instance] updateStatusBar:nil]; return YES; diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 2b60f1c18..a83129c80 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -632,6 +632,7 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "backgroundmode_preference", isbackgroundModeEnabled); + lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "start_at_boot_preference", [self boolForKey:@"start_at_boot_preference"]); BOOL firstloginview = [self boolForKey:@"enable_first_login_view_preference"]; lp_config_set_int(config, LINPHONERC_APPLICATION_KEY, "enable_first_login_view_preference", firstloginview); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 29e9fe102..191087fd8 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1127,7 +1127,7 @@ static BOOL libStarted = FALSE; if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { //go directly to bg mode - [self resignActive]; + [self enterBackgroundMode]; } } @@ -1157,7 +1157,9 @@ static BOOL libStarted = FALSE; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionInterrupted:) name:AVAudioSessionInterruptionNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(globalStateChangedNotificationHandler:) name:kLinphoneGlobalStateUpdate object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(configuringStateChangedNotificationHandler:) name:kLinphoneConfiguringStateUpdate object:nil]; - + + /*call iterate once immediately in order to initiate background connections with sip server, if any */ + linphone_core_iterate(theLinphoneCore); // start scheduler mIterateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self @@ -1273,6 +1275,7 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) - (void) startCallPausedLongRunningTask { pausedCallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ [LinphoneLogger log:LinphoneLoggerWarning format:@"Call cannot be paused any more, too late"]; + [[UIApplication sharedApplication] endBackgroundTask:pausedCallBgTask]; }]; [LinphoneLogger log:LinphoneLoggerLog format:@"Long running task started, remaining [%g s] because at least one call is paused" ,[[UIApplication sharedApplication] backgroundTimeRemaining]]; diff --git a/submodules/belle-sip b/submodules/belle-sip index eb3467af3..fd8d52069 160000 --- a/submodules/belle-sip +++ b/submodules/belle-sip @@ -1 +1 @@ -Subproject commit eb3467af3e8f42c5a9cea36d4253bd66641413f3 +Subproject commit fd8d52069e00261b99f6bb03b78342418ddb6da4 diff --git a/submodules/linphone b/submodules/linphone index 811223d35..7553aa649 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 811223d35f6ae1f7831f7b918cb95b1e1e7bcf0d +Subproject commit 7553aa6492f1df0106ca42bbfb9cea49c5dd656e