From 1c08ea1791c540c442d664b37c1e4e484b3c6cf3 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 20 Oct 2014 15:34:02 +0200 Subject: [PATCH] Add possibility to send logs using enable_log_collect in linphonerc [app] section --- Classes/LinphoneManager.m | 16 +++++++ Classes/SettingsViewController.h | 2 +- Classes/SettingsViewController.m | 59 +++++++++++++++++++++++- Resources/linphonerc | 1 + Settings/InAppSettings.bundle/Root.plist | 10 +++- submodules/belle-sip | 2 +- submodules/linphone | 2 +- 7 files changed, 87 insertions(+), 5 deletions(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index c3c603f81..80aea349b 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1337,6 +1337,10 @@ static BOOL libStarted = FALSE; ,configDb ,self /* user_data */); + + linphone_core_set_log_collection_path([[LinphoneManager cacheDirectory] UTF8String]); + linphone_core_enable_log_collection([self lpConfigBoolForKey:@"enable_log_collect"]); + /* set the CA file no matter what, since the remote provisioning could be hitting an HTTPS server */ const char* lRootCa = [[LinphoneManager bundleFile:@"rootca.pem"] cStringUsingEncoding:[NSString defaultCStringEncoding]]; linphone_core_set_root_ca(theLinphoneCore, lRootCa); @@ -1864,6 +1868,18 @@ static void audioRouteChangeListenerCallback ( return [documentsPath stringByAppendingPathComponent:file]; } ++ (NSString*)cacheDirectory { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *cachePath = [paths objectAtIndex:0]; + BOOL isDir = NO; + NSError *error; + // cache directory must be created if not existing + if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) { + [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error]; + } + return cachePath; +} + + (int)unreadMessageCount { int count = 0; if( [LinphoneManager isLcReady] ){ diff --git a/Classes/SettingsViewController.h b/Classes/SettingsViewController.h index 49358e650..91dd60905 100644 --- a/Classes/SettingsViewController.h +++ b/Classes/SettingsViewController.h @@ -23,7 +23,7 @@ #import "IASKAppSettingsViewController.h" #import "LinphoneCoreSettingsStore.h" -@interface SettingsViewController: UIViewController { +@interface SettingsViewController: UIViewController { @private LinphoneCoreSettingsStore* settingsStore; } diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index af73214e2..34240e758 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -640,6 +640,10 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys addObject:@"clear_cache_button"]; [hiddenKeys addObject:@"battery_alert_button"]; #endif + + if (! [[LinphoneManager instance] lpConfigBoolForKey:@"enable_log_collect"]) { + [hiddenKeys addObject:@"send_logs_button"]; + } [hiddenKeys addObject:@"playback_gain_preference"]; [hiddenKeys addObject:@"microphone_gain_preference"]; @@ -752,7 +756,32 @@ static UICompositeViewDescription *compositeDescription = nil; [alert release]; } else if([key isEqual:@"about_button"]) { [[PhoneMainView instance] changeCurrentView:[AboutViewController compositeViewDescription] push:TRUE]; - } + } else if ([key isEqual:@"send_logs_button"]) { + char * filepath = linphone_core_compress_log_collection([LinphoneManager getLc]); + if (filepath == NULL) { + [LinphoneLogger log:LinphoneLoggerError format:@"Cannot sent logs: file is NULL"]; + return; + } + + NSString *filename = [[NSString stringWithUTF8String:filepath] componentsSeparatedByString:@"/"].lastObject; + NSString *mimeType; + if ([filename hasSuffix:@".jpg"]) { + mimeType = @"image/jpeg"; + } else if ([filename hasSuffix:@".png"]) { + mimeType = @"image/png"; + } else if ([filename hasSuffix:@".pdf"]) { + mimeType = @"application/pdf"; + } else if ([filename hasSuffix:@".txt"]) { + mimeType = @"text/plain"; + } else if ([filename hasSuffix:@".gz"]) { + mimeType = @"application/gzip"; + } else { + [LinphoneLogger log:LinphoneLoggerError format:@"Unknown extension type: %@, cancelling email", filename]; + return; + } + [self emailAttachment:[NSData dataWithContentsOfFile:[NSString stringWithUTF8String:filepath]] mimeType:mimeType name:filename]; + ms_free(filepath); + } } #pragma mark - UIAlertView delegate @@ -766,5 +795,33 @@ static UICompositeViewDescription *compositeDescription = nil; } } +#pragma mark - Mail composer for send log +- (void)emailAttachment: (NSData*)attachment mimeType:(NSString*)type name:(NSString*)attachmentName +{ + if (attachmentName == nil || type == nil || attachmentName == nil) { + [LinphoneLogger log:LinphoneLoggerError format:@"Trying to email attachment but mandatory field is missing"]; + return; + } + MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; + picker.mailComposeDelegate = self; + + [picker setSubject:NSLocalizedString(@"Linphone Logs",nil)]; + [picker setToRecipients:[NSArray arrayWithObjects:@"linphone-iphone@belledonne-communications.com", nil]]; + [picker setMessageBody:NSLocalizedString(@"Linphone logs", nil) isHTML:NO]; + [picker addAttachmentData:attachment mimeType:type fileName:attachmentName]; + + [self presentViewController:picker animated:true completion:nil]; + [picker release]; +} + +- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error +{ + if (error != nil) { + [LinphoneLogger log:LinphoneLoggerWarning format:@"Error while sending mail: %@", error]; + } else { + [LinphoneLogger log:LinphoneLoggerLog format:@"Mail completed with status: %d", result]; + } + [self dismissViewControllerAnimated:true completion:nil]; +} @end diff --git a/Resources/linphonerc b/Resources/linphonerc index 360d286b7..be46954f2 100644 --- a/Resources/linphonerc +++ b/Resources/linphonerc @@ -37,6 +37,7 @@ start_at_boot_preference=1 backgroundmode_preference=1 autoanswer_notif_preference=1 voiceproc_preference=1 +enable_log_collect=0 [default_values] reg_expires=600 \ No newline at end of file diff --git a/Settings/InAppSettings.bundle/Root.plist b/Settings/InAppSettings.bundle/Root.plist index dccfa9342..465ecfb68 100644 --- a/Settings/InAppSettings.bundle/Root.plist +++ b/Settings/InAppSettings.bundle/Root.plist @@ -260,7 +260,7 @@ Key release_button Title - Release + Exit Type IASKButtonSpecifier @@ -280,6 +280,14 @@ Type IASKButtonSpecifier + + Key + send_logs_button + Title + Send debug logs + Type + IASKButtonSpecifier + StringsTable Root diff --git a/submodules/belle-sip b/submodules/belle-sip index eee5149dd..afa02ac71 160000 --- a/submodules/belle-sip +++ b/submodules/belle-sip @@ -1 +1 @@ -Subproject commit eee5149dde1ab04249e8d3d83676fa15d0ef78b6 +Subproject commit afa02ac712906b36fdc21526ecf87659e31fade2 diff --git a/submodules/linphone b/submodules/linphone index 2479a567a..78acd91a5 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 2479a567a5a49a7a63406b3b1bf3f7a536a03d54 +Subproject commit 78acd91a54a0cca244df68475cdc158f03608322