Add Debug Popup Code for displaying and sharing LinphoneRC file (#1234# in Dialer)

This commit is contained in:
Benoit Martins 2023-05-03 13:37:17 +02:00
parent bff4491da7
commit 90c26b3f8c
5 changed files with 102 additions and 33 deletions

View file

@ -285,16 +285,10 @@ static UICompositeViewDescription *compositeDescription = nil;
- (BOOL)displayDebugPopup:(NSString *)address {
LinphoneManager *mgr = LinphoneManager.instance;
NSString *debugAddress = [mgr lpConfigStringForKey:@"debug_popup_magic" withDefault:@""];
if (![debugAddress isEqualToString:@""] && [address isEqualToString:debugAddress]) {
if (TRUE) {
UIAlertController *errView = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Debug", nil)
message:NSLocalizedString(@"Choose an action", nil)
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[errView addAction:defaultAction];
int debugLevel = [LinphoneManager.instance lpConfigIntForKey:@"debugenable_preference"];
BOOL debugEnabled = (debugLevel >= ORTP_DEBUG && debugLevel < ORTP_ERROR);
@ -322,31 +316,21 @@ static UICompositeViewDescription *compositeDescription = nil;
}];
[errView addAction:logAction];
UIAlertAction* remAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Remove account(s) and self destruct", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
linphone_core_clear_accounts([LinphoneManager getLc]);
linphone_core_clear_all_auth_info([LinphoneManager getLc]);
@try {
[LinphoneManager.instance destroyLinphoneCore];
} @catch (NSException *e) {
LOGW(@"Exception while destroying linphone core: %@", e);
} @finally {
if ([NSFileManager.defaultManager
isDeletableFileAtPath:[LinphoneManager preferenceFile:@"linphonerc"]] == YES) {
[NSFileManager.defaultManager
removeItemAtPath:[LinphoneManager preferenceFile:@"linphonerc"]
error:nil];
}
#ifdef DEBUG
[LinphoneManager instanceRelease];
#endif
}
[UIApplication sharedApplication].keyWindow.rootViewController = nil;
// make the application crash to be sure that user restart it properly
LOGF(@"Self-destructing in 3..2..1..0!");
}];
[errView addAction:remAction];
UIAlertAction* configAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"View config file", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
TextViewer *view = VIEW(TextViewer);
view.textViewer = [NSString stringWithContentsOfFile:[LinphoneManager bundleFile:@"linphonerc"] encoding:NSUTF8StringEncoding error:nil];
[PhoneMainView.instance popToView:view.compositeViewDescription];
}];
[errView addAction:configAction];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[errView addAction:defaultAction];
[self presentViewController:errView animated:YES completion:nil];
return true;
@ -419,7 +403,8 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (IBAction)onAddressChange:(id)sender {
if ([self displayDebugPopup:_addressField.text]) {
if ([_addressField.text isEqual: @"#1234#"]) {
[self displayDebugPopup:_addressField.text];
_addressField.text = @"";
}
LinphoneAccount *defaultAccount = linphone_core_get_default_account(LC);

View file

@ -0,0 +1,72 @@
//
// TextViewer.swift
// linphone
//
// Created by Benoît Martins on 03/05/2023.
//
import Foundation
@objc class TextViewer: BackNextNavigationView, UICompositeViewDelegate {
static let compositeDescription = UICompositeViewDescription(TextViewer.self, statusBar: StatusBarView.self, tabBar: nil, sideMenu: SideMenuView.self, fullscreen: false, isLeftFragment: false,fragmentWith: nil)
static func compositeViewDescription() -> UICompositeViewDescription! { return compositeDescription }
func compositeViewDescription() -> UICompositeViewDescription! { return type(of: self).compositeDescription }
@objc var textViewer = ""
let textViewViewer = UITextView()
override func viewDidLoad() {
super.viewDidLoad(
backAction: {
PhoneMainView.instance().popView(self.compositeViewDescription())
},nextAction: {
},
nextActionEnableCondition: MutableLiveData(false),
title:"")
super.nextButton.isHidden = true
let shareButton = CallControlButton(buttonTheme:VoipTheme.nav_button("voip_export"))
super.topBar.addSubview(shareButton)
shareButton.alignParentRight(withMargin: side_buttons_margin).alignParentBottom(withMargin: 18).alignParentTop(withMargin: 18).done()
shareButton.addTarget(self, action: #selector(shareTextButton), for: .touchUpInside)
super.backButton.isHidden = UIDevice.ipad()
textViewViewer.isScrollEnabled = true
textViewViewer.isUserInteractionEnabled = true
textViewViewer.frame = CGRect(x: 0, y: top_bar_height, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height-top_bar_height*2-32.0)
self.view.addSubview(textViewViewer)
UIDeviceBridge.displayModeSwitched.readCurrentAndObserve { _ in
self.view.backgroundColor = VoipTheme.voipBackgroundBWColor.get()
self.textViewViewer.frame = CGRect(x: 0, y: self.top_bar_height, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height - (self.top_bar_height * 2) - 32.0)
}
}
override func viewDidAppear(_ animated: Bool) {
textViewViewer.text = textViewer
}
@IBAction func shareTextButton(_ sender: UIButton) {
// text to share
let text = textViewer
// set up activity view controller
let textToShare = [ text ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}
}

View file

@ -941,6 +941,7 @@
D3F795D615A582810077328B /* ChatConversationView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F795D415A582800077328B /* ChatConversationView.m */; };
D3F7998115BD32370018C273 /* TPMultiLayoutViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F7998015BD32370018C273 /* TPMultiLayoutViewController.m */; };
D3F83F8E15822ABE00336684 /* PhoneMainView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F83F8D15822ABD00336684 /* PhoneMainView.m */; };
D7DA18712A02598700FABA0D /* TextViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DA18702A02598700FABA0D /* TextViewer.swift */; };
EA0007A62356008F003CC6BF /* msgNotificationService.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = EA5F25D9232BD3E200475F2E /* msgNotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
EA3650DB2330D2E30001148A /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F25DB232BD3E200475F2E /* NotificationService.swift */; };
EA88A405242A6216007FEC61 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 63AADBC41B6A0FF200AA16FD /* Localizable.strings */; };
@ -2169,6 +2170,7 @@
D3F7998015BD32370018C273 /* TPMultiLayoutViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TPMultiLayoutViewController.m; path = Utils/TPMultiLayoutViewController/TPMultiLayoutViewController.m; sourceTree = "<group>"; };
D3F83F8C158229C500336684 /* PhoneMainView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PhoneMainView.h; sourceTree = "<group>"; };
D3F83F8D15822ABD00336684 /* PhoneMainView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhoneMainView.m; sourceTree = "<group>"; };
D7DA18702A02598700FABA0D /* TextViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewer.swift; sourceTree = "<group>"; };
EA5F25D9232BD3E200475F2E /* msgNotificationService.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = msgNotificationService.appex; sourceTree = BUILT_PRODUCTS_DIR; };
EA5F25DB232BD3E200475F2E /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
EA5F25DD232BD3E200475F2E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -3422,6 +3424,7 @@
C63F71AA285A24B10066163B /* Util */ = {
isa = PBXGroup;
children = (
D7DA18722A02599A00FABA0D /* Viewers */,
C63F71AB285A24B10066163B /* ViewModel */,
C63F71AD285A24B10066163B /* MutableLiveData.swift */,
C63F71AE285A24B10066163B /* Pair.swift */,
@ -3780,6 +3783,14 @@
name = TPMultiLayoutViewController;
sourceTree = "<group>";
};
D7DA18722A02599A00FABA0D /* Viewers */ = {
isa = PBXGroup;
children = (
D7DA18702A02598700FABA0D /* TextViewer.swift */,
);
path = Viewers;
sourceTree = "<group>";
};
EA5F25DA232BD3E200475F2E /* msgNotificationService */ = {
isa = PBXGroup;
children = (
@ -5036,6 +5047,7 @@
C63F7233285A24B10066163B /* ConferenceExtensions.swift in Sources */,
C63F7260285A24B10066163B /* StyledSwitch.swift in Sources */,
C63F7252285A24B10066163B /* VoipExtraButtonsView.swift in Sources */,
D7DA18712A02598700FABA0D /* TextViewer.swift in Sources */,
669B140C27A29D140012220A /* FloatingScrollDownButton.swift in Sources */,
C63F7219285A24B10066163B /* ConferenceHistoryDetailsView.swift in Sources */,
D3A8BB7015A6C7D500F96BE5 /* UIChatBubbleTextCell.m in Sources */,