check callid from push notif before auto accepting call

This commit is contained in:
Jehan Monnier 2012-10-03 09:48:05 +02:00
parent 581dccc7a8
commit 9f7f8a97cb
6 changed files with 42 additions and 19 deletions

View file

@ -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 !"];
}
}
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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) {

View file

@ -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);

@ -1 +1 @@
Subproject commit 61312092bbda523c8fa98c9804d123a5308d2e57
Subproject commit 5f348a03c29f71c9d536a7dd3baf257259de8f39