Improve battery warning

Improve logs
This commit is contained in:
Yann Diorcet 2012-12-07 11:01:34 +01:00
parent 2b72e4598c
commit 6900913b59
8 changed files with 57 additions and 45 deletions

View file

@ -590,8 +590,12 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
BOOL debugmode = [self boolForKey:@"debugenable_preference"];
lp_config_set_int(linphone_core_get_config(lc), LINPHONERC_APPLICATION_KEY, "debugenable_preference", debugmode);
if (debugmode) linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler);
else linphone_core_disable_logs();
if (debugmode) {
linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler);
ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
} else {
linphone_core_disable_logs();
}
[[NSUserDefaults standardUserDefaults] setBool:debugmode forKey:@"debugenable_preference"]; //to be used at linphone core startup
BOOL animations = [self boolForKey:@"animations_preference"];

View file

@ -82,7 +82,7 @@ extern void libmsbcg729_init();
if ((self = [super init])) {
self->batteryWarningShown = FALSE;
self->notification = nil;
self->videoRequested=FALSE;
self->videoRequested = FALSE;
self->userInfos = [[NSMutableDictionary alloc] init];
}
return self;
@ -379,14 +379,11 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char
- (void)onCall:(LinphoneCall*)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message {
// Handling wrapper
LinphoneCallAppData* data=nil;
if (!linphone_call_get_user_pointer(call)) {
LinphoneCallAppData* data=(LinphoneCallAppData*)linphone_call_get_user_pointer(call);
if (!data) {
data = [[LinphoneCallAppData alloc] init];
linphone_call_set_user_pointer(call, data);
} else {
data = (LinphoneCallAppData*) linphone_call_get_user_pointer(call);
}
}
if (state == LinphoneCallIncomingReceived) {
@ -795,6 +792,7 @@ static LinphoneCoreVTable linphonec_vtable = {
/*to make sure we don't loose debug trace*/
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"debugenable_preference"]) {
linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler);
ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
}
[LinphoneLogger logc:LinphoneLoggerLog format:"Create linphonecore"];
linphone_core_set_user_agent([@"LinphoneIPhone" UTF8String],
@ -1142,7 +1140,7 @@ static void audioRouteChangeListenerCallback (
if([self lpConfigBoolForKey:@"edge_opt_preference"]) {
bool low_bandwidth = self.network == network_2g;
if(low_bandwidth) {
[LinphoneLogger log:LinphoneLoggerDebug format:@"Low bandwidth mode"];
[LinphoneLogger log:LinphoneLoggerLog format:@"Low bandwidth mode"];
}
linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth);
}
@ -1183,7 +1181,7 @@ static void audioRouteChangeListenerCallback (
if([self lpConfigBoolForKey:@"edge_opt_preference"]) {
bool low_bandwidth = self.network == network_2g;
if(low_bandwidth) {
[LinphoneLogger log:LinphoneLoggerDebug format:@"Low bandwidth mode"];
[LinphoneLogger log:LinphoneLoggerLog format:@"Low bandwidth mode"];
}
linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth);
}

View file

@ -350,7 +350,7 @@
}
}
if(remove) {
[LinphoneLogger log:LinphoneLoggerDebug format:@"Free cached view: %@", key];
[LinphoneLogger log:LinphoneLoggerLog format:@"Free cached view: %@", key];
UIViewController *vc = [viewControllerCache objectForKey:key];
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 5.0) {
[vc viewWillUnload];

View file

@ -47,6 +47,7 @@
int loadCount;
NSMutableArray *viewStack;
NSMutableArray *inhibitedEvents;
NSTimer *batteryTimer;
}
@property (nonatomic, retain) IBOutlet UICompositeViewController *mainViewController;

View file

@ -116,6 +116,8 @@ static PhoneMainView* phoneMainViewInstance=nil;
name:UIDeviceBatteryLevelDidChangeNotification
object:nil];
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
batteryTimer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(batteryLevelChanged:) userInfo:nil repeats:TRUE];
}
- (void)viewWillDisappear:(BOOL)animated {
@ -139,6 +141,8 @@ static PhoneMainView* phoneMainViewInstance=nil;
name:UIDeviceBatteryLevelDidChangeNotification
object:nil];
[[UIDevice currentDevice] setBatteryMonitoringEnabled:NO];
[batteryTimer invalidate];
}
- (void)viewDidAppear:(BOOL)animated {
@ -577,30 +581,35 @@ static PhoneMainView* phoneMainViewInstance=nil;
}
- (void)batteryLevelChanged:(NSNotification*)notif {
float level = [UIDevice currentDevice].batteryLevel;
UIDeviceBatteryState state = [UIDevice currentDevice].batteryState;
[LinphoneLogger log:LinphoneLoggerLog format:@"Battery state:%d level:%.2f", state, level];
if (![LinphoneManager isLcReady]) return;
LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]);
if (!call || !linphone_call_params_video_enabled(linphone_call_get_current_params(call)))
return;
LinphoneCallAppData* appData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call);
float level = [UIDevice currentDevice].batteryLevel;
if ([UIDevice currentDevice].batteryState == UIDeviceBatteryStateUnplugged) {
[LinphoneLogger logc:LinphoneLoggerLog format:"Video call is running. Battery level: %.2f", level];
if (level < 0.1 && !appData->batteryWarningShown) {
DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Battery is running low. Stop video ?",nil)] autorelease];
[sheet addCancelButtonWithTitle:NSLocalizedString(@"Continue video", nil)];
[sheet addDestructiveButtonWithTitle:NSLocalizedString(@"Stop video", nil) block:^() {
LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call));
// stop video
linphone_call_params_enable_video(paramsCopy, FALSE);
linphone_core_update_call([LinphoneManager getLc], call, paramsCopy);
}];
[sheet showInView:self.view];
appData->batteryWarningShown = TRUE;
if (call && linphone_call_params_video_enabled(linphone_call_get_current_params(call))) {
LinphoneCallAppData* callData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call);
if(callData != nil) {
if (state == UIDeviceBatteryStateUnplugged) {
if (level <= 0.2f && !callData->batteryWarningShown) {
[LinphoneLogger log:LinphoneLoggerLog format:@"Battery warning"];
DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Battery is running low. Stop video ?",nil)] autorelease];
[sheet addCancelButtonWithTitle:NSLocalizedString(@"Continue video", nil)];
[sheet addDestructiveButtonWithTitle:NSLocalizedString(@"Stop video", nil) block:^() {
LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call));
// stop video
linphone_call_params_enable_video(paramsCopy, FALSE);
linphone_core_update_call([LinphoneManager getLc], call, paramsCopy);
}];
[sheet showInView:self.view];
callData->batteryWarningShown = TRUE;
}
}
if (level > 0.2f) {
callData->batteryWarningShown = FALSE;
}
}
}
if (level >= 0.1) {
appData->batteryWarningShown = FALSE;
}
}

View file

@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">784</int>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.SystemVersion">11G63</string>
<string key="IBDocument.InterfaceBuilderVersion">2840</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.AppKitVersion">1138.51</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>

View file

@ -27,10 +27,10 @@
va_list args;
va_start (args, format);
NSString *str = [[NSString alloc] initWithFormat: format arguments:args];
if(severity <= LinphoneLoggerLog) {
ms_message("%s", [str UTF8String]);
} else if(severity <= LinphoneLoggerDebug) {
if(severity <= LinphoneLoggerDebug) {
ms_debug("%s", [str UTF8String]);
} else if(severity <= LinphoneLoggerLog) {
ms_message("%s", [str UTF8String]);
} else if(severity <= LinphoneLoggerWarning) {
ms_warning("%s", [str UTF8String]);
} else if(severity <= LinphoneLoggerError) {
@ -45,13 +45,13 @@
+ (void)logc:(LinphoneLoggerSeverity) severity format:(const char *)format,... {
va_list args;
va_start (args, format);
if(severity <= LinphoneLoggerLog) {
ortp_logv(ORTP_MESSAGE, format, args);
} else if(severity <= LinphoneLoggerDebug) {
if(severity <= LinphoneLoggerDebug) {
ortp_logv(ORTP_DEBUG, format, args);
} else if(severity <= LinphoneLoggerLog) {
ortp_logv(ORTP_MESSAGE, format, args);
} else if(severity <= LinphoneLoggerWarning) {
ortp_logv(ORTP_WARNING, format, args);
} else if(severity <= LinphoneLoggerError) {
} else if(severity <= LinphoneLoggerError) {
ortp_logv(ORTP_ERROR, format, args);
} else if(severity <= LinphoneLoggerFatal) {
ortp_logv(ORTP_FATAL, format, args);

View file

@ -374,7 +374,7 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)checkUserExist:(NSString*)username {
[LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC check_account %@", username];
[LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC check_account %@", username];
NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]];
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL];
@ -389,7 +389,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)createAccount:(NSString*)identity password:(NSString*)password email:(NSString*)email {
NSString *useragent = [LinphoneManager getUserAgent];
[LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC create_account_with_useragent %@ %@ %@ %@", identity, password, email, useragent];
[LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC create_account_with_useragent %@ %@ %@ %@", identity, password, email, useragent];
NSURL *URL = [NSURL URLWithString: [[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]];
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL];
@ -403,7 +403,7 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)checkAccountValidation:(NSString*)identity {
[LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC check_account_validated %@", identity];
[LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC check_account_validated %@", identity];
NSURL *URL = [NSURL URLWithString: [[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]];
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL];
@ -659,7 +659,7 @@ static UICompositeViewDescription *compositeDescription = nil;
#pragma mark - XMLRPCConnectionDelegate Functions
- (void)request:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response {
[LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC %@: %@", [request method], [response body]];
[LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC %@: %@", [request method], [response body]];
[waitView setHidden:true];
if ([response isFault]) {
NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Communication issue (%@)", nil), [response faultString]];