mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-23 06:08:07 +00:00
Better handling of GSM call (with or without bg mode enabled)
This commit is contained in:
parent
c4d938d1fb
commit
ddd82ee253
6 changed files with 60 additions and 35 deletions
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AddressBookUI/ABPeoplePickerNavigationController.h>
|
||||
#import "CoreTelephony/CTCallCenter.h"
|
||||
|
||||
#define DIALER_TAB_INDEX 1
|
||||
#define CONTACTS_TAB_INDEX 2
|
||||
|
|
@ -39,7 +40,8 @@
|
|||
IBOutlet PhoneViewController* myPhoneViewController;
|
||||
CallHistoryTableViewController* myCallHistoryTableViewController;
|
||||
ContactPickerDelegate* myContactPickerDelegate;
|
||||
|
||||
|
||||
CTCallCenter* callCenter;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UIWindow *window;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,24 @@ int __aeabi_idiv(int a, int b) {
|
|||
@synthesize myPeoplePickerController;
|
||||
@synthesize myPhoneViewController;
|
||||
|
||||
-(void) handleGSMCallInteration: (id) cCenter {
|
||||
CTCallCenter* ct = (CTCallCenter*) cCenter;
|
||||
|
||||
int callCount = [ct.currentCalls count];
|
||||
if (!callCount) {
|
||||
NSLog(@"No GSM call -> enabling SIP calls");
|
||||
linphone_core_set_max_calls([LinphoneManager getLc], 3);
|
||||
} else {
|
||||
NSLog(@"%d GSM call(s) -> disabling SIP calls", callCount);
|
||||
/* pause current call, if any */
|
||||
LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]);
|
||||
if (call) {
|
||||
NSLog(@"Pausing SIP call");
|
||||
linphone_core_pause_call([LinphoneManager getLc], call);
|
||||
}
|
||||
linphone_core_set_max_calls([LinphoneManager getLc], 0);
|
||||
}
|
||||
}
|
||||
|
||||
-(void)applicationWillResignActive:(UIApplication *)application {
|
||||
LinphoneCore* lc = [LinphoneManager getLc];
|
||||
|
|
@ -65,11 +83,31 @@ int __aeabi_idiv(int a, int b) {
|
|||
|
||||
}
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
[[LinphoneManager instance] enterBackgroundMode];
|
||||
if (![[LinphoneManager instance] enterBackgroundMode]) {
|
||||
// destroying eventHandler if app cannot go in background.
|
||||
// Otherwise if a GSM call happen and Linphone is resumed,
|
||||
// the handler will be called before LinphoneCore is built.
|
||||
// Then handler will be restored in appDidBecomeActive cb
|
||||
callCenter.callEventHandler = nil;
|
||||
[callCenter release];
|
||||
callCenter = nil;
|
||||
}
|
||||
}
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
[[LinphoneManager instance] becomeActive];
|
||||
|
||||
if (callCenter == nil) {
|
||||
callCenter = [[CTCallCenter alloc] init];
|
||||
callCenter.callEventHandler = ^(CTCall* call) {
|
||||
// post on main thread
|
||||
[self performSelectorOnMainThread:@selector(handleGSMCallInteration:)
|
||||
withObject:callCenter
|
||||
waitUntilDone:YES];
|
||||
};
|
||||
}
|
||||
// check call state at startup
|
||||
[self handleGSMCallInteration:callCenter];
|
||||
|
||||
LinphoneCore* lc = [LinphoneManager getLc];
|
||||
LinphoneCall* call = linphone_core_get_current_call(lc);
|
||||
if (call == NULL)
|
||||
|
|
@ -130,6 +168,7 @@ int __aeabi_idiv(int a, int b) {
|
|||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
|
||||
/*
|
||||
|
|
@ -182,30 +221,12 @@ int __aeabi_idiv(int a, int b) {
|
|||
|
||||
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound];
|
||||
|
||||
CTCallCenter* ct = [[CTCallCenter alloc] init];
|
||||
ct.callEventHandler = ^(CTCall* call) {
|
||||
@synchronized([LinphoneManager instance]) {
|
||||
if (call.callState == CTCallStateDisconnected) {
|
||||
NSLog(@"GSM call disconnected");
|
||||
if ([ct.currentCalls count] > 0) {
|
||||
NSLog(@"There are still some ongoing GSM call: disable SIP calls");
|
||||
linphone_core_set_max_calls([LinphoneManager getLc], 0);
|
||||
} else {
|
||||
NSLog(@"Re-enabling SIP calls");
|
||||
linphone_core_set_max_calls([LinphoneManager getLc], 3);
|
||||
}
|
||||
} else {
|
||||
NSLog(@"GSM call existing");
|
||||
/* pause current call, if any */
|
||||
LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]);
|
||||
if (call) {
|
||||
NSLog(@"Pausing SIP call");
|
||||
linphone_core_pause_call([LinphoneManager getLc], call);
|
||||
}
|
||||
NSLog(@"Disabling SIP calls");
|
||||
linphone_core_set_max_calls([LinphoneManager getLc], 0);
|
||||
}
|
||||
}
|
||||
callCenter = [[CTCallCenter alloc] init];
|
||||
callCenter.callEventHandler = ^(CTCall* call) {
|
||||
// post on main thread
|
||||
[self performSelectorOnMainThread:@selector(handleGSMCallInteration:)
|
||||
withObject:callCenter
|
||||
waitUntilDone:YES];
|
||||
};
|
||||
return YES;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ typedef struct _CallContext {
|
|||
-(BOOL) isNotIphone3G;
|
||||
-(void) destroyLibLinphone;
|
||||
|
||||
-(void) enterBackgroundMode;
|
||||
-(BOOL) enterBackgroundMode;
|
||||
-(void) becomeActive;
|
||||
-(void) kickOffNetworkConnection;
|
||||
-(NSString*) getDisplayNameFromAddressBook:(NSString*) number andUpdateCallLog:(LinphoneCallLog*)log;
|
||||
|
|
|
|||
|
|
@ -693,6 +693,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
|
|||
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
|
||||
[audioSession setDelegate:nil];
|
||||
if (theLinphoneCore != nil) { //just in case application terminate before linphone core initialization
|
||||
NSLog(@"Destroy linphonecore");
|
||||
linphone_core_destroy(theLinphoneCore);
|
||||
theLinphoneCore = nil;
|
||||
SCNetworkReachabilityUnscheduleFromRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
||||
|
|
@ -704,7 +705,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
|
|||
}
|
||||
|
||||
//**********************BG mode management*************************///////////
|
||||
-(void) enterBackgroundMode {
|
||||
-(BOOL) enterBackgroundMode {
|
||||
LinphoneProxyConfig* proxyCfg;
|
||||
linphone_core_get_default_proxy(theLinphoneCore, &proxyCfg);
|
||||
linphone_core_stop_dtmf_stream(theLinphoneCore);
|
||||
|
|
@ -744,11 +745,12 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
|
|||
if (linphone_core_get_sip_transports(theLinphoneCore, &transportValue)) {
|
||||
ms_error("cannot get current transport");
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
ms_warning("Entering lite bg mode");
|
||||
[self destroyLibLinphone];
|
||||
return NO;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -802,6 +804,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
|
|||
#endif
|
||||
/* Initialize linphone core*/
|
||||
|
||||
NSLog(@"Create linphonecore");
|
||||
theLinphoneCore = linphone_core_new (&linphonec_vtable
|
||||
, [confiFileName cStringUsingEncoding:[NSString defaultCStringEncoding]]
|
||||
, [factoryConfig cStringUsingEncoding:[NSString defaultCStringEncoding]]
|
||||
|
|
@ -891,13 +894,12 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach
|
|||
|
||||
}
|
||||
-(void) becomeActive {
|
||||
|
||||
if (theLinphoneCore == nil) {
|
||||
//back from standby and background mode is disabled
|
||||
[self startLibLinphone];
|
||||
} else {
|
||||
if (![self reconfigureLinphoneIfNeeded:currentSettings]) {
|
||||
ms_message("becomming active with no config modification, make sure we are registered");
|
||||
ms_message("becoming active with no config modification, make sure we are registered");
|
||||
linphone_core_refresh_registers(theLinphoneCore);//just to make sure REGISTRATION is up to date
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
}
|
||||
|
||||
-(BOOL) updateWithRegistrationState:(LinphoneRegistrationState)state message:(NSString*) message {
|
||||
|
||||
label.hidden = NO;
|
||||
switch(state) {
|
||||
case LinphoneRegistrationCleared:
|
||||
image.hidden = NO;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
<array class="NSMutableArray" key="NSSubviews">
|
||||
<object class="IBUIImageView" id="332800514">
|
||||
<reference key="NSNextResponder" ref="848661322"/>
|
||||
<int key="NSvFlags">292</int>
|
||||
<int key="NSvFlags">-2147483356</int>
|
||||
<string key="NSFrame">{{0, -1}, {25, 23}}</string>
|
||||
<reference key="NSSuperview" ref="848661322"/>
|
||||
<reference key="NSWindow"/>
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
</object>
|
||||
<object class="IBUILabel" id="200467549">
|
||||
<reference key="NSNextResponder" ref="848661322"/>
|
||||
<int key="NSvFlags">292</int>
|
||||
<int key="NSvFlags">-2147483356</int>
|
||||
<string key="NSFrame">{{28, 0}, {280, 21}}</string>
|
||||
<reference key="NSSuperview" ref="848661322"/>
|
||||
<reference key="NSWindow"/>
|
||||
|
|
@ -76,7 +76,7 @@
|
|||
<int key="IBUIContentMode">7</int>
|
||||
<bool key="IBUIUserInteractionEnabled">NO</bool>
|
||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
||||
<string key="IBUIText">No SIP account defined</string>
|
||||
<string key="IBUIText">CARAMBA</string>
|
||||
<object class="NSColor" key="IBUITextColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue