debug: "Send logs" button is now also attaching linphone.rc and linphone-chats.db

This commit is contained in:
Gautier Pelloux-Prayer 2015-09-18 11:47:33 +02:00
parent 021dae7e38
commit 87f7fa5fbf
3 changed files with 106 additions and 64 deletions

View file

@ -568,7 +568,7 @@ static void dump_section(const char *section, void *data) {
lp_config_for_each_entry((const LpConfig *)data, section, dump_entry, &d);
}
+ (void)dumpLCConfig {
+ (void)dumpLcConfig {
if (theLinphoneCore) {
LpConfig *conf = [LinphoneManager instance].configDb;
lp_config_for_each_section(conf, dump_section, conf);
@ -1067,25 +1067,26 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat
}
static void showNetworkFlags(SCNetworkReachabilityFlags flags) {
LOGI(@"Network connection flags:");
NSMutableString *log = [[NSMutableString alloc] initWithString:@"Network connection flags: "];
if (flags == 0)
LOGI(@"no flags.");
[log appendString:@"no flags."];
if (flags & kSCNetworkReachabilityFlagsTransientConnection)
LOGI(@"kSCNetworkReachabilityFlagsTransientConnection");
[log appendString:@"kSCNetworkReachabilityFlagsTransientConnection, "];
if (flags & kSCNetworkReachabilityFlagsReachable)
LOGI(@"kSCNetworkReachabilityFlagsReachable");
[log appendString:@"kSCNetworkReachabilityFlagsReachable, "];
if (flags & kSCNetworkReachabilityFlagsConnectionRequired)
LOGI(@"kSCNetworkReachabilityFlagsConnectionRequired");
[log appendString:@"kSCNetworkReachabilityFlagsConnectionRequired, "];
if (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic)
LOGI(@"kSCNetworkReachabilityFlagsConnectionOnTraffic");
[log appendString:@"kSCNetworkReachabilityFlagsConnectionOnTraffic, "];
if (flags & kSCNetworkReachabilityFlagsConnectionOnDemand)
LOGI(@"kSCNetworkReachabilityFlagsConnectionOnDemand");
[log appendString:@"kSCNetworkReachabilityFlagsConnectionOnDemand, "];
if (flags & kSCNetworkReachabilityFlagsIsLocalAddress)
LOGI(@"kSCNetworkReachabilityFlagsIsLocalAddress");
[log appendString:@"kSCNetworkReachabilityFlagsIsLocalAddress, "];
if (flags & kSCNetworkReachabilityFlagsIsDirect)
LOGI(@"kSCNetworkReachabilityFlagsIsDirect");
[log appendString:@"kSCNetworkReachabilityFlagsIsDirect, "];
if (flags & kSCNetworkReachabilityFlagsIsWWAN)
LOGI(@"kSCNetworkReachabilityFlagsIsWWAN");
[log appendString:@"kSCNetworkReachabilityFlagsIsWWAN, "];
LOGI(@"%@", log);
}
static void networkReachabilityNotification(CFNotificationCenterRef center, void *observer, CFStringRef name,

View file

@ -741,32 +741,31 @@ static UICompositeViewDescription *compositeDescription = nil;
} else if ([key isEqualToString:@"reset_logs_button"]) {
linphone_core_reset_log_collection();
} else if ([key isEqual:@"send_logs_button"]) {
char *filepath = linphone_core_compress_log_collection(lc);
if (filepath == NULL) {
LOGE(@"Cannot sent logs: file is NULL");
return;
NSString *message;
if ([LinphoneManager.instance lpConfigBoolForKey:@"send_logs_include_linphonerc_and_chathistory"]) {
message = NSLocalizedString(
@"Warning: an email will be created with 3 attachments:\n- Application "
@"logs\n- Linphone configuration\n- Chats history.\nThey may contain "
@"private informations (MIGHT contain clear-text password!).\nYou can remove one or several "
@"of these attachments before sending your email, however there are all "
@"important to diagnostize your issue.",
nil);
} else {
message = NSLocalizedString(@"Warning: an email will be created with application " @"logs. It may contain "
@"private informations (but no password!).\nThese logs are "
@"important to diagnostize your issue.",
nil);
}
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 {
LOGE(@"Unknown extension type: %@, cancelling email", filename);
return;
}
[self emailAttachment:[NSData dataWithContentsOfFile:[NSString stringWithUTF8String:filepath]]
mimeType:mimeType
name:filename];
ms_free(filepath);
DTAlertView *alert =
[[DTAlertView alloc] initWithTitle:NSLocalizedString(@"Sending logs", nil) message:message];
[alert addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil];
[alert addButtonWithTitle:NSLocalizedString(@"I got it, continue", nil)
block:^{
[self sendEmailWithDebugAttachments];
}];
[alert show];
}
}
@ -779,45 +778,86 @@ static UICompositeViewDescription *compositeDescription = nil;
[self goToWizard];
}
#pragma mark - Mail composer for send log
- (void)emailAttachment:(NSData *)attachment mimeType:(NSString *)type name:(NSString *)attachmentName {
if (attachmentName == nil || type == nil || attachmentName == nil) {
LOGE(@"Trying to email attachment but mandatory field is missing");
return;
#pragma mark - Mail composer for sending logs
- (void)sendEmailWithDebugAttachments {
LinphoneCore *lc = [LinphoneManager getLc];
NSMutableArray *attachments = [[NSMutableArray alloc] initWithCapacity:3];
// retrieve linphone logs if available
char *filepath = linphone_core_compress_log_collection(lc);
if (filepath != NULL) {
NSString *filename = [[NSString stringWithUTF8String:filepath] componentsSeparatedByString:@"/"].lastObject;
NSString *mimeType = nil;
if ([filename hasSuffix:@".txt"]) {
mimeType = @"text/plain";
} else if ([filename hasSuffix:@".gz"]) {
mimeType = @"application/gzip";
} else {
LOGE(@"Unknown extension type: %@, not attaching logs", filename);
}
if (mimeType != nil) {
[attachments addObject:@[ [NSString stringWithUTF8String:filepath], mimeType, filename ]];
}
}
if ([LinphoneManager.instance lpConfigBoolForKey:@"send_logs_include_linphonerc_and_chathistory"]) {
// retrieve linphone rc
[attachments
addObject:@[ [LinphoneManager documentFile:@"linphonerc"], @"text/plain", @"linphone-configuration.rc" ]];
// retrieve historydb
[attachments addObject:@[
[LinphoneManager documentFile:@"linphone_chats.db"],
@"application/x-sqlite3",
@"linphone-chats-history.db"
]];
}
[self emailAttachments:attachments];
ms_free(filepath);
}
- (void)emailAttachments:(NSArray *)attachments {
NSString *error = nil;
#if TARGET_IPHONE_SIMULATOR
UIAlertView *error = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Cannot send email", nil)
message:NSLocalizedString(
@"Simulator cannot send emails. To test this feature, please use a real device.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Continue", nil)
otherButtonTitles:nil];
[error show];
error =
NSLocalizedString(@"Cannot send emails on the Simulator. To test this feature, please use a real device.", nil);
#else
if ([MFMailComposeViewController canSendMail] == YES) {
if ([MFMailComposeViewController canSendMail] == NO) {
error = NSLocalizedString(
@"Your device is not configured to send emails. Please configure mail application prior to send logs.",
nil);
}
#endif
if (error != nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Cannot send email", nil)
message:error
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Continue", nil)
otherButtonTitles:nil];
[alert show];
} else {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:NSLocalizedString(@"Linphone Logs", nil)];
[picker setSubject:NSLocalizedString(@"Linphone iOS 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];
[picker setMessageBody:NSLocalizedString(@"Here are information about an issue I had on my device.\nI was "
@"doing ...\nI expected Linphone to ...\nInstead, I got an "
@"unexpected result: ...",
nil)
isHTML:NO];
for (NSArray *attachment in attachments) {
if ([[NSFileManager defaultManager] fileExistsAtPath:attachment[0]]) {
[picker addAttachmentData:[NSData dataWithContentsOfFile:attachment[0]]
mimeType:attachment[1]
fileName:attachment[2]];
}
}
[self presentViewController:picker animated:true completion:nil];
} else {
UIAlertView *error = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Cannot send email", nil)
message:NSLocalizedString(@"Your device is not configured to send emails. Please configure mail "
@"application prior to send logs.",
nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Continue", nil)
otherButtonTitles:nil];
[error show];
}
#endif
}
- (void)mailComposeController:(MFMailComposeViewController *)controller

View file

@ -18,6 +18,7 @@ display_filter_auto_rotate=0
#contact_display_username_only=1
#contact_filter_on_default_domain=1
#use_phone_number=0
send_logs_include_linphonerc_and_chathistory=0
[in_app_purchase]
enabled=0