diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 47d7dd61d..d788dc58a 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -201,7 +201,7 @@ } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - [LinphoneLogger log:LinphoneLoggerDebug format:@"PushNotification: Receive %@", userInfo]; + [LinphoneLogger log:LinphoneLoggerLog format:@"PushNotification: Receive %@", userInfo]; NSDictionary *aps = [userInfo objectForKey:@"aps"]; if(aps != nil) { NSDictionary *alert = [aps objectForKey:@"alert"]; @@ -218,7 +218,10 @@ [[PhoneMainView instance] changeCurrentView:[ChatViewController compositeViewDescription]]; } else if([loc_key isEqualToString:@"IC_MSG"]) { //it's a call - [[LinphoneManager instance] didReceiveRemoteNotification]; + if ([alert objectForKey:@"call-id"]) + [[LinphoneManager instance] enableAutoAnswerForCallId:[alert objectForKey:@"call-id"]]; + else + [LinphoneLogger log:LinphoneLoggerError format:@"PushNotification: does not have call-id yet, fix it !"]; } } } diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index e31492bd9..0c03037fb 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -81,7 +81,7 @@ typedef struct _LinphoneManagerSounds { @private NSTimer* mIterateTimer; - time_t lastRemoteNotificationTime; + NSMutableArray* pendindCallIdFromRemoteNotif; Connectivity connectivity; BOOL stopWaitingRegisters; @@ -105,9 +105,9 @@ typedef struct _LinphoneManagerSounds { - (BOOL)resignActive; - (void)becomeActive; - (BOOL)enterBackgroundMode; -- (void)didReceiveRemoteNotification; +- (void)enableAutoAnswerForCallId:(NSString*) callid; - (void)addPushTokenToProxyConfig: (LinphoneProxyConfig*)cfg; -- (BOOL)shouldAutoAcceptCall; +- (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId; - (void)waitForRegisterToArrive; + (void)kickOffNetworkConnection; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index b38fde7f4..8686fd83c 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -221,7 +221,7 @@ struct codec_name_pref_table codec_pref_table[]={ speakerEnabled = FALSE; [self openDatabase]; [self copyDefaultSettings]; - lastRemoteNotificationTime=0; + pendindCallIdFromRemoteNotif = [[NSMutableArray alloc] init ]; photoLibrary = [[ALAssetsLibrary alloc] init]; } return self; @@ -245,6 +245,7 @@ struct codec_name_pref_table codec_pref_table[]={ } [photoLibrary release]; + [pendindCallIdFromRemoteNotif release]; [super dealloc]; } @@ -769,16 +770,30 @@ static LinphoneCoreVTable linphonec_vtable = { } } - -- (void)didReceiveRemoteNotification{ - lastRemoteNotificationTime=time(NULL); +static int comp_call_id (const LinphoneCall* call , const char *callid) { + return strcmp(linphone_call_get_call_log(call)->call_id, callid) == 0; +} +- (void)enableAutoAnswerForCallId:(NSString*) callid{ + //first, make sure this callid is not already involved in a call + if ([LinphoneManager isLcReady]) { + MSList* calls = (MSList*)linphone_core_get_calls([LinphoneManager getLc]); + if (ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String])) { + [LinphoneLogger log:LinphoneLoggerWarning format:@"Call id [%@] already handle",callid]; + return; + }; + } + if ([pendindCallIdFromRemoteNotif count] > 10 /*max number of pending notif*/) + [pendindCallIdFromRemoteNotif removeObjectAtIndex:0]; + [pendindCallIdFromRemoteNotif addObject:callid]; + } -- (BOOL)shouldAutoAcceptCall{ - if (lastRemoteNotificationTime!=0){ - if ((time(NULL)-lastRemoteNotificationTime)<15) - return TRUE; - lastRemoteNotificationTime=0; +- (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId{ + for (NSString* pendingNotif in pendindCallIdFromRemoteNotif) { + if ([pendingNotif compare:callId] == NSOrderedSame) { + [pendindCallIdFromRemoteNotif removeObject:pendingNotif]; + return TRUE; + } } return FALSE; } diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index 1d7913855..90cd30892 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -216,7 +216,8 @@ NSTimer *callSecurityTimer; if([LinphoneManager isLcReady]) { LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); if(call != NULL) { - float quality = linphone_call_get_average_quality(call); + //FIXME double check call state before computing, may cause core dump + float quality = linphone_call_get_average_quality(call); if(quality < 1) { image = [UIImage imageNamed:@"call_quality_indicator_0.png"]; } else if (quality < 2) { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 874189546..e4e9c49ee 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -654,6 +654,8 @@ static PhoneMainView* phoneMainViewInstance=nil; - (void)displayIncomingCall:(LinphoneCall*) call{ LinphoneCallAppData* appData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call); + LinphoneCallLog* callLog=linphone_call_get_call_log(call); + NSString* callId=[NSString stringWithUTF8String:callLog->call_id]; if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { @@ -684,7 +686,8 @@ static PhoneMainView* phoneMainViewInstance=nil; if(address == nil) { address = @"Unknown"; } - if (![[LinphoneManager instance] shouldAutoAcceptCall]){ + + if (![[LinphoneManager instance] shouldAutoAcceptCallForCallId:callId]){ // case where a remote notification is not already received // Create a new local notification appData->notification = [[UILocalNotification alloc] init]; @@ -695,11 +698,12 @@ static PhoneMainView* phoneMainViewInstance=nil; appData->notification.soundName = @"ring.caf"; appData->notification.userInfo = [NSDictionary dictionaryWithObject:[NSData dataWithBytes:&call length:sizeof(call)] forKey:@"call"]; - [[UIApplication sharedApplication] presentLocalNotificationNow:appData->notification]; + [[LinphoneManager instance] enableAutoAnswerForCallId:callId]; + [[UIApplication sharedApplication] presentLocalNotificationNow:appData->notification]; } } } else { - if ([[LinphoneManager instance] shouldAutoAcceptCall]){ + if ([[LinphoneManager instance] shouldAutoAcceptCallForCallId:callId]){ linphone_core_accept_call(linphone_call_get_core(call),call); }else{ IncomingCallViewController *controller = DYNAMIC_CAST([self changeCurrentView:[IncomingCallViewController compositeViewDescription] push:TRUE],IncomingCallViewController); diff --git a/submodules/linphone b/submodules/linphone index 61312092b..5f348a03c 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 61312092bbda523c8fa98c9804d123a5308d2e57 +Subproject commit 5f348a03c29f71c9d536a7dd3baf257259de8f39