mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Merge branch 'feature/logs' into 'master'
Add various utility files, and specifically Log See merge request BC/private/linphone-iphone-6.0!13
This commit is contained in:
commit
4e44d764f8
9 changed files with 581 additions and 8 deletions
|
|
@ -7,6 +7,11 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
66C491F92B24D25B00CEA16D /* ConfigExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491F82B24D25A00CEA16D /* ConfigExtension.swift */; };
|
||||
66C491FB2B24D32600CEA16D /* CoreExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FA2B24D32600CEA16D /* CoreExtension.swift */; };
|
||||
66C491FD2B24D36500CEA16D /* AudioRouteUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FC2B24D36500CEA16D /* AudioRouteUtils.swift */; };
|
||||
66C491FF2B24D4AC00CEA16D /* FileUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FE2B24D4AC00CEA16D /* FileUtils.swift */; };
|
||||
66C492012B24DB6900CEA16D /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C492002B24DB6900CEA16D /* Log.swift */; };
|
||||
D706BA822ADD72D100278F45 /* DeviceRotationViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D706BA812ADD72D100278F45 /* DeviceRotationViewModifier.swift */; };
|
||||
D70C93DE2AC2D0F60063CA3B /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = D70C93DD2AC2D0F60063CA3B /* Localizable.xcstrings */; };
|
||||
D717071E2AC5922E0037746F /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D717071D2AC5922E0037746F /* ColorExtension.swift */; };
|
||||
|
|
@ -86,6 +91,11 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
66C491F82B24D25A00CEA16D /* ConfigExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigExtension.swift; sourceTree = "<group>"; };
|
||||
66C491FA2B24D32600CEA16D /* CoreExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreExtension.swift; sourceTree = "<group>"; };
|
||||
66C491FC2B24D36500CEA16D /* AudioRouteUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRouteUtils.swift; sourceTree = "<group>"; };
|
||||
66C491FE2B24D4AC00CEA16D /* FileUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUtils.swift; sourceTree = "<group>"; };
|
||||
66C492002B24DB6900CEA16D /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
|
||||
D706BA812ADD72D100278F45 /* DeviceRotationViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceRotationViewModifier.swift; sourceTree = "<group>"; };
|
||||
D70C93DD2AC2D0F60063CA3B /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
|
||||
D717071D2AC5922E0037746F /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -178,6 +188,17 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
66C491F72B24D25A00CEA16D /* Extensions */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D717071D2AC5922E0037746F /* ColorExtension.swift */,
|
||||
66C491F82B24D25A00CEA16D /* ConfigExtension.swift */,
|
||||
D76005F52B0798B00054B79A /* IntExtension.swift */,
|
||||
D717071F2AC5989C0037746F /* TextExtension.swift */,
|
||||
);
|
||||
path = Extensions;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A31AF2AB8C6A3D7B7EA3B424 /* Pods */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -188,15 +209,16 @@
|
|||
D717071C2AC591EF0037746F /* Utils */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D717071D2AC5922E0037746F /* ColorExtension.swift */,
|
||||
D717071F2AC5989C0037746F /* TextExtension.swift */,
|
||||
D76005F52B0798B00054B79A /* IntExtension.swift */,
|
||||
D74C9D002ACB098C0021626A /* PermissionManager.swift */,
|
||||
D7D1698B2AE66FA500109A5C /* MagicSearchSingleton.swift */,
|
||||
D7C3650D2AF15BF200FE6142 /* PhotoPicker.swift */,
|
||||
D7C48DF32AFA66F900D938CB /* EditContactController.swift */,
|
||||
D732A9082AFD235500DB42BA /* ShareSheetController.swift */,
|
||||
66C491F72B24D25A00CEA16D /* Extensions */,
|
||||
66C491FC2B24D36500CEA16D /* AudioRouteUtils.swift */,
|
||||
D7ADF5FF2AFE356400212231 /* Avatar.swift */,
|
||||
D7C48DF32AFA66F900D938CB /* EditContactController.swift */,
|
||||
66C491FE2B24D4AC00CEA16D /* FileUtils.swift */,
|
||||
66C492002B24DB6900CEA16D /* Log.swift */,
|
||||
D7D1698B2AE66FA500109A5C /* MagicSearchSingleton.swift */,
|
||||
D74C9D002ACB098C0021626A /* PermissionManager.swift */,
|
||||
D7C3650D2AF15BF200FE6142 /* PhotoPicker.swift */,
|
||||
D732A9082AFD235500DB42BA /* ShareSheetController.swift */,
|
||||
);
|
||||
path = Utils;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -272,6 +294,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
D719ABC82ABC6FD700B41C10 /* CoreContext.swift */,
|
||||
66C491FA2B24D32600CEA16D /* CoreExtension.swift */,
|
||||
);
|
||||
path = Core;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -570,6 +593,7 @@
|
|||
D7C3650E2AF15BF200FE6142 /* PhotoPicker.swift in Sources */,
|
||||
D7ADF6002AFE356400212231 /* Avatar.swift in Sources */,
|
||||
D71707202AC5989C0037746F /* TextExtension.swift in Sources */,
|
||||
66C491F92B24D25B00CEA16D /* ConfigExtension.swift in Sources */,
|
||||
D719ABB92ABC67BF00B41C10 /* ContentView.swift in Sources */,
|
||||
D71FCA832AE14D6E00D2E43E /* ContactFragment.swift in Sources */,
|
||||
D7C3650C2AF0084000FE6142 /* EditContactViewModel.swift in Sources */,
|
||||
|
|
@ -578,6 +602,7 @@
|
|||
D706BA822ADD72D100278F45 /* DeviceRotationViewModifier.swift in Sources */,
|
||||
D732A9132B04C7A300DB42BA /* HistoryListFragment.swift in Sources */,
|
||||
D719ABC92ABC6FD700B41C10 /* CoreContext.swift in Sources */,
|
||||
66C491FD2B24D36500CEA16D /* AudioRouteUtils.swift in Sources */,
|
||||
D7EAACCF2AD6ED8000AA6A8A /* PermissionsFragment.swift in Sources */,
|
||||
D777DBB32AE12C5900565A99 /* ContactsManager.swift in Sources */,
|
||||
D796F2002B0BB61A0041115F /* ToastViewModel.swift in Sources */,
|
||||
|
|
@ -591,6 +616,7 @@
|
|||
D7B5066D2AEFA9B900CEB4E9 /* ContactInnerFragment.swift in Sources */,
|
||||
D7E6D04D2AEBD77600A57AAF /* CustomBottomSheet.swift in Sources */,
|
||||
D7C48DF42AFA66F900D938CB /* EditContactController.swift in Sources */,
|
||||
66C491FF2B24D4AC00CEA16D /* FileUtils.swift in Sources */,
|
||||
D74C9D012ACB098C0021626A /* PermissionManager.swift in Sources */,
|
||||
D7702EF22AC7205000557C00 /* WelcomeView.swift in Sources */,
|
||||
D732A9152B04C7FE00DB42BA /* HistoryListViewModel.swift in Sources */,
|
||||
|
|
@ -606,6 +632,7 @@
|
|||
D7A03FC62ACC458A0081A588 /* SplashScreen.swift in Sources */,
|
||||
D7A03FC02ACC2E390081A588 /* HistoryView.swift in Sources */,
|
||||
D748BF2E2ACD82E7004844EB /* ThirdPartySipAccountWarningFragment.swift in Sources */,
|
||||
66C492012B24DB6900CEA16D /* Log.swift in Sources */,
|
||||
D748BF2C2ACD82D2004844EB /* ThirdPartySipAccountLoginFragment.swift in Sources */,
|
||||
D74C9CF82ACACECE0021626A /* WelcomePage1Fragment.swift in Sources */,
|
||||
D7E6D0552AEBFCCE00A57AAF /* ContactsInnerFragment.swift in Sources */,
|
||||
|
|
@ -615,6 +642,7 @@
|
|||
D7C48DF62AFCDF4700D938CB /* ContactInnerActionsFragment.swift in Sources */,
|
||||
D72343322ACEFF58009AA24E /* QRScannerController.swift in Sources */,
|
||||
D72343342ACEFFC3009AA24E /* QRScanner.swift in Sources */,
|
||||
66C491FB2B24D32600CEA16D /* CoreExtension.swift in Sources */,
|
||||
D726E43D2B19E4FE0083C415 /* StartCallFragment.swift in Sources */,
|
||||
D72343302ACEFEF8009AA24E /* QrCodeScannerFragment.swift in Sources */,
|
||||
D726E43F2B19E56F0083C415 /* StartCallViewModel.swift in Sources */,
|
||||
|
|
|
|||
44
Linphone/Core/CoreExtension.swift
Normal file
44
Linphone/Core/CoreExtension.swift
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Core Extension provides a set of utilies to manage automatically a LinphoneCore no matter if it is from App or an extension.
|
||||
// It is based on a singleton pattern and adds.
|
||||
|
||||
import UIKit
|
||||
import linphonesw
|
||||
|
||||
struct CoreError: Error {
|
||||
let message: String
|
||||
init(_ message: String) {
|
||||
self.message = message
|
||||
}
|
||||
public var localizedDescription: String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
||||
extension Core {
|
||||
|
||||
public static func runsInsideExtension() -> Bool { // Tells wether it is run inside app extension or the main app.
|
||||
let bundleUrl: URL = Bundle.main.bundleURL
|
||||
let bundlePathExtension: String = bundleUrl.pathExtension
|
||||
return bundlePathExtension == "appex"
|
||||
}
|
||||
|
||||
}
|
||||
197
Linphone/Utils/AudioRouteUtils.swift
Normal file
197
Linphone/Utils/AudioRouteUtils.swift
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// swiftlint:disable line_length
|
||||
|
||||
import Foundation
|
||||
import AVFoundation
|
||||
import linphonesw
|
||||
|
||||
class AudioRouteUtils {
|
||||
|
||||
static private func applyAudioRouteChange( core: Core, call: Call?, types: [AudioDevice.Kind], output: Bool = true) {
|
||||
let typesNames = types.map { String(describing: $0) }.joined(separator: "/")
|
||||
|
||||
let currentCall = core.callsNb > 0 ? (call != nil) ? call : core.currentCall != nil ? core.currentCall : core.calls[0] : nil
|
||||
if currentCall == nil {
|
||||
print("[Audio Route Helper] No call found, setting audio route on Core")
|
||||
}
|
||||
let conference = call?.conference
|
||||
let capability = output ? AudioDevice.Capabilities.CapabilityPlay : AudioDevice.Capabilities.CapabilityRecord
|
||||
|
||||
var found = false
|
||||
|
||||
core.audioDevices.forEach { (audioDevice) in
|
||||
print("[Audio Route Helper] registered core audio devices are : [\(audioDevice.deviceName)] [\(audioDevice.type)] [\(audioDevice.capabilities)] ")
|
||||
}
|
||||
|
||||
core.audioDevices.forEach { (audioDevice) in
|
||||
if !found && types.contains(audioDevice.type) && audioDevice.hasCapability(capability: capability) {
|
||||
if conference != nil && conference?.isIn == true {
|
||||
print("[Audio Route Helper] Found [\(audioDevice.type)] \(output ? "playback" : "recorder") audio device [\(audioDevice.deviceName)], routing conference audio to it")
|
||||
if output {
|
||||
conference?.outputAudioDevice = audioDevice
|
||||
} else {
|
||||
conference?.inputAudioDevice = audioDevice
|
||||
}
|
||||
} else if currentCall != nil {
|
||||
print("[Audio Route Helper] Found [\(audioDevice.type)] \(output ? "playback" : "recorder") audio device [\(audioDevice.deviceName)], routing call audio to it")
|
||||
if output {
|
||||
currentCall?.outputAudioDevice = audioDevice
|
||||
} else {
|
||||
currentCall?.inputAudioDevice = audioDevice
|
||||
}
|
||||
} else {
|
||||
print("[Audio Route Helper] Found [\(audioDevice.type)] \(output ? "playback" : "recorder") audio device [\(audioDevice.deviceName)], changing core default audio device")
|
||||
if output {
|
||||
core.outputAudioDevice = audioDevice
|
||||
} else {
|
||||
core.inputAudioDevice = audioDevice
|
||||
}
|
||||
}
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
print("[Audio Route Helper] Couldn't find \(typesNames) audio device")
|
||||
}
|
||||
}
|
||||
|
||||
static private func changeCaptureDeviceToMatchAudioRoute(core: Core, call: Call?, types: [AudioDevice.Kind]) {
|
||||
switch types.first {
|
||||
case .Bluetooth: if isBluetoothAudioRecorderAvailable(core: core) {
|
||||
print("[Audio Route Helper] Bluetooth device is able to record audio, also change input audio device")
|
||||
applyAudioRouteChange(core: core, call: call, types: [AudioDevice.Kind.Bluetooth], output: false)
|
||||
}
|
||||
case .Headset, .Headphones: if isHeadsetAudioRecorderAvailable(core: core) {
|
||||
print("[Audio Route Helper] Headphones/headset device is able to record audio, also change input audio device")
|
||||
applyAudioRouteChange(core: core, call: call, types: [AudioDevice.Kind.Headphones, AudioDevice.Kind.Headset], output: false)
|
||||
}
|
||||
default: applyAudioRouteChange(core: core, call: call, types: [AudioDevice.Kind.Microphone], output: false)
|
||||
}
|
||||
}
|
||||
|
||||
static private func routeAudioTo(core: Core, call: Call?, types: [AudioDevice.Kind]) {
|
||||
let currentCall = call != nil ? call : core.currentCall != nil ? core.currentCall : (core.callsNb > 0 ? core.calls[0] : nil)
|
||||
if call != nil || currentCall != nil {
|
||||
let callToUse = call != nil ? call : currentCall
|
||||
applyAudioRouteChange(core: core, call: callToUse, types: types)
|
||||
changeCaptureDeviceToMatchAudioRoute(core: core, call: callToUse, types: types)
|
||||
} else {
|
||||
applyAudioRouteChange(core: core, call: call, types: types)
|
||||
changeCaptureDeviceToMatchAudioRoute(core: core, call: call, types: types)
|
||||
}
|
||||
}
|
||||
|
||||
static func routeAudioToEarpiece(core: Core, call: Call? = nil) {
|
||||
routeAudioTo(core: core, call: call, types: [AudioDevice.Kind.Microphone]) // on iOS Earpiece = Microphone
|
||||
}
|
||||
|
||||
static func routeAudioToSpeaker(core: Core, call: Call? = nil) {
|
||||
routeAudioTo(core: core, call: call, types: [AudioDevice.Kind.Speaker])
|
||||
}
|
||||
|
||||
static func routeAudioToSpeaker(core: Core) {
|
||||
routeAudioTo(core: core, call: nil, types: [AudioDevice.Kind.Speaker])
|
||||
}
|
||||
|
||||
static func routeAudioToBluetooth(core: Core, call: Call? = nil) {
|
||||
routeAudioTo(core: core, call: call, types: [AudioDevice.Kind.Bluetooth])
|
||||
}
|
||||
|
||||
static func routeAudioToHeadset(core: Core, call: Call? = nil) {
|
||||
routeAudioTo(core: core, call: call, types: [AudioDevice.Kind.Headphones, AudioDevice.Kind.Headset])
|
||||
}
|
||||
|
||||
static func isSpeakerAudioRouteCurrentlyUsed(core: Core, call: Call? = nil) -> Bool {
|
||||
|
||||
let currentCall = core.callsNb > 0 ? (call != nil) ? call : core.currentCall != nil ? core.currentCall : core.calls[0] : nil
|
||||
if currentCall == nil {
|
||||
print("[Audio Route Helper] No call found, setting audio route on Core")
|
||||
}
|
||||
|
||||
let conference = core.conference
|
||||
let audioDevice = conference != nil && conference?.isIn == true ? conference!.outputAudioDevice : currentCall != nil ? currentCall!.outputAudioDevice : core.outputAudioDevice
|
||||
print("[Audio Route Helper] Playback audio currently in use is [\(audioDevice?.deviceName ?? "n/a")] with type (\(audioDevice?.type ?? .Unknown)")
|
||||
return audioDevice?.type == AudioDevice.Kind.Speaker
|
||||
}
|
||||
|
||||
static func isBluetoothAudioRouteCurrentlyUsed(core: Core, call: Call? = nil) -> Bool {
|
||||
if core.callsNb == 0 {
|
||||
print("[Audio Route Helper] No call found, so bluetooth audio route isn't used")
|
||||
return false
|
||||
}
|
||||
let currentCall = call != nil ? call : core.currentCall != nil ? core.currentCall : core.calls[0]
|
||||
let conference = core.conference
|
||||
|
||||
let audioDevice = conference != nil && conference?.isIn == true ? conference!.outputAudioDevice : currentCall?.outputAudioDevice
|
||||
print("[Audio Route Helper] Playback audio device currently in use is [\(audioDevice?.deviceName ?? "n/a")] with type (\(audioDevice?.type ?? .Unknown)")
|
||||
return audioDevice?.type == AudioDevice.Kind.Bluetooth
|
||||
}
|
||||
|
||||
static func isBluetoothAudioRouteAvailable(core: Core) -> Bool {
|
||||
if let device = core.audioDevices.first(where: { $0.type == AudioDevice.Kind.Bluetooth && $0.hasCapability(capability: .CapabilityPlay) }) {
|
||||
print("[Audio Route Helper] Found bluetooth audio device [\(device.deviceName)]")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
static private func isBluetoothAudioRecorderAvailable(core: Core) -> Bool {
|
||||
if let device = core.audioDevices.first(where: { $0.type == AudioDevice.Kind.Bluetooth && $0.hasCapability(capability: .CapabilityRecord) }) {
|
||||
print("[Audio Route Helper] Found bluetooth audio recorder [\(device.deviceName)]")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
static func isHeadsetAudioRouteAvailable(core: Core) -> Bool {
|
||||
if let device = core.audioDevices.first(where: { ($0.type == AudioDevice.Kind.Headset||$0.type == AudioDevice.Kind.Headphones) && $0.hasCapability(capability: .CapabilityPlay) }) {
|
||||
print("[Audio Route Helper] Found headset/headphones audio device [\(device.deviceName)]")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
static private func isHeadsetAudioRecorderAvailable(core: Core) -> Bool {
|
||||
if let device = core.audioDevices.first(where: { ($0.type == AudioDevice.Kind.Headset||$0.type == AudioDevice.Kind.Headphones) && $0.hasCapability(capability: .CapabilityRecord) }) {
|
||||
print("[Audio Route Helper] Found headset/headphones audio recorder [\(device.deviceName)]")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
static func isReceiverEnabled(core: Core) -> Bool {
|
||||
if let outputDevice = core.outputAudioDevice {
|
||||
return outputDevice.type == AudioDevice.Kind.Microphone
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
static func isBluetoothAvailable(core: Core) -> Bool {
|
||||
for device in core.audioDevices {
|
||||
if device.type == AudioDevice.Kind.Bluetooth || device.type == AudioDevice.Kind.BluetoothA2DP {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
// swiftlint:enable line_length
|
||||
63
Linphone/Utils/Extensions/ConfigExtension.swift
Normal file
63
Linphone/Utils/Extensions/ConfigExtension.swift
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import Foundation
|
||||
import linphonesw
|
||||
|
||||
// Singleton that manages the Shared Config between app and app extension.
|
||||
|
||||
extension Config {
|
||||
|
||||
private static var _instance : Config?
|
||||
|
||||
public func getDouble(section:String, key:String, defaultValue:Double) -> Double {
|
||||
if (self.hasEntry(section: section, key: key) != 1) {
|
||||
return defaultValue
|
||||
}
|
||||
let stringValue = self.getString(section: section, key: key, defaultString: "")
|
||||
return Double(stringValue) ?? defaultValue
|
||||
}
|
||||
|
||||
public static func get() -> Config {
|
||||
if _instance == nil {
|
||||
let factoryPath = FileUtil.bundleFilePath(Core.runsInsideExtension() ? "linphonerc-factory-appex" : "linphonerc-factory-app")!
|
||||
_instance = Config.newForSharedCore(appGroupId: Config.appGroupName, configFilename: "linphonerc", factoryConfigFilename: factoryPath)!
|
||||
}
|
||||
return _instance!
|
||||
}
|
||||
|
||||
public func getString(section: String, key: String) -> String? {
|
||||
return hasEntry(section: section, key: key) == 1 ? getString(section: section, key: key, defaultString: "") : nil
|
||||
}
|
||||
|
||||
static let appGroupName = "group.org.linphone.phone.logs"
|
||||
// Needs to be the same name in App Group (capabilities in ALL targets - app & extensions - content + service), can't be stored in the Config itself the Config needs this value to get created
|
||||
static let teamID = Config.get().getString(section: "app", key: "team_id", defaultString: "")
|
||||
static let earlymediaContentExtensionCagetoryIdentifier = Config.get().getString(section: "app", key: "extension_category", defaultString: "")
|
||||
|
||||
// Default values in app
|
||||
static let serveraddress = Config.get().getString(section: "app", key: "server", defaultString: "")
|
||||
static let defaultUsername = Config.get().getString(section: "app", key: "user", defaultString: "")
|
||||
static let defaultPass = Config.get().getString(section: "app", key: "pass", defaultString: "")
|
||||
|
||||
static let pushNotificationsInterval = Config.get().getInt(section: "net", key: "pn-call-remote-push-interval", defaultValue: 3)
|
||||
|
||||
}
|
||||
125
Linphone/Utils/FileUtils.swift
Normal file
125
Linphone/Utils/FileUtils.swift
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linhome
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import UIKit
|
||||
import linphonesw
|
||||
|
||||
class FileUtil: NSObject {
|
||||
public class func bundleFilePath(_ file: NSString) -> String? {
|
||||
return Bundle.main.path(forResource: file.deletingPathExtension, ofType: file.pathExtension)
|
||||
}
|
||||
|
||||
public class func bundleFilePathAsUrl(_ file: NSString) -> URL? {
|
||||
if let bPath = bundleFilePath(file) {
|
||||
return URL.init(fileURLWithPath: bPath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public class func documentsDirectory() -> URL {
|
||||
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
let documentsDirectory = paths[0]
|
||||
return documentsDirectory
|
||||
}
|
||||
|
||||
public class func libraryDirectory() -> URL {
|
||||
let paths = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)
|
||||
let documentsDirectory = paths[0]
|
||||
return documentsDirectory
|
||||
}
|
||||
|
||||
public class func sharedContainerUrl() -> URL {
|
||||
return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: Config.appGroupName)!
|
||||
}
|
||||
|
||||
public class func ensureDirectoryExists(path: String) {
|
||||
if !FileManager.default.fileExists(atPath: path) {
|
||||
do {
|
||||
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class func ensureFileExists(path: String) {
|
||||
if !FileManager.default.fileExists(atPath: path) {
|
||||
FileManager.default.createFile(atPath: path, contents: nil, attributes: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public class func fileExists(path: String) -> Bool {
|
||||
return FileManager.default.fileExists(atPath: path)
|
||||
}
|
||||
|
||||
public class func fileExistsAndIsNotEmpty(path: String) -> Bool {
|
||||
guard FileManager.default.fileExists(atPath: path) else {return false}
|
||||
do {
|
||||
let attribute = try FileManager.default.attributesOfItem(atPath: path)
|
||||
if let size = attribute[FileAttributeKey.size] as? NSNumber {
|
||||
return size.doubleValue > 0
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public class func write(string: String, toPath: String) {
|
||||
do {
|
||||
try string.write(to: URL(fileURLWithPath: toPath), atomically: true, encoding: String.Encoding.utf8)
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
public class func delete(path: String) {
|
||||
do {
|
||||
try FileManager.default.removeItem(atPath: path)
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
public class func copy(_ fromPath: String, _ toPath: String, overWrite: Bool) {
|
||||
do {
|
||||
if overWrite && fileExists(path: toPath) {
|
||||
delete(path: toPath)
|
||||
}
|
||||
try FileManager.default.copyItem(at: URL(fileURLWithPath: fromPath), to: URL(fileURLWithPath: toPath))
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
// For debugging
|
||||
|
||||
public class func showListOfFilesInSharedDir() {
|
||||
let fileManager = FileManager.default
|
||||
do {
|
||||
let fileURLs = try fileManager.contentsOfDirectory(at: FileUtil.sharedContainerUrl(), includingPropertiesForKeys: nil)
|
||||
fileURLs.forEach { print($0) }
|
||||
} catch {
|
||||
print("Error while enumerating files \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
116
Linphone/Utils/Log.swift
Normal file
116
Linphone/Utils/Log.swift
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// swiftlint:disable line_length
|
||||
|
||||
// Singleton instance that logs both info from the App and from the core, using the core log level. ([app] log_level parameter in linphonerc-factory-app
|
||||
|
||||
import UIKit
|
||||
import os
|
||||
import linphonesw
|
||||
import linphone
|
||||
|
||||
class Log: LoggingServiceDelegate {
|
||||
|
||||
static let instance = Log()
|
||||
|
||||
var debugEnabled = true // Todo : bind to app parameters
|
||||
var service = LoggingService.Instance
|
||||
|
||||
private init() {
|
||||
service.domain = Bundle.main.bundleIdentifier!
|
||||
// CRASH TO BE FIXED ??
|
||||
//Core.setLogCollectionPath(path: Factory.Instance.getDownloadDir(context: UnsafeMutablePointer<Int8>(mutating: (Config.appGroupName as NSString).utf8String)))
|
||||
Core.enableLogCollection(state: LogCollectionState.Enabled)
|
||||
setMask()
|
||||
LoggingService.Instance.addDelegate(delegate: self)
|
||||
|
||||
}
|
||||
|
||||
func setMask() {
|
||||
if debugEnabled {
|
||||
LoggingService.Instance.logLevelMask = UInt(LogLevel.Fatal.rawValue + LogLevel.Error.rawValue + LogLevel.Warning.rawValue + LogLevel.Message.rawValue + LogLevel.Trace.rawValue + LogLevel.Debug.rawValue)
|
||||
} else {
|
||||
LoggingService.Instance.logLevelMask = UInt(LogLevel.Fatal.rawValue + LogLevel.Error.rawValue + LogLevel.Warning.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
let levelToStrings: [Int: String] =
|
||||
[LogLevel.Debug.rawValue: "Debug"
|
||||
, LogLevel.Trace.rawValue: "Trace"
|
||||
, LogLevel.Message.rawValue: "Message"
|
||||
, LogLevel.Warning.rawValue: "Warning"
|
||||
, LogLevel.Error.rawValue: "Error"
|
||||
, LogLevel.Fatal.rawValue: "Fatal"]
|
||||
|
||||
let levelToOSleLogLevel: [Int: OSLogType] =
|
||||
[LogLevel.Debug.rawValue: .debug,
|
||||
LogLevel.Trace.rawValue: .info,
|
||||
LogLevel.Message.rawValue: .info,
|
||||
LogLevel.Warning.rawValue: .error,
|
||||
LogLevel.Error.rawValue: .error,
|
||||
LogLevel.Fatal.rawValue: .fault]
|
||||
|
||||
public class func debug(_ message: String) {
|
||||
instance.service.debug(message: message)
|
||||
}
|
||||
public class func info(_ message: String) {
|
||||
instance.service.message(message: message)
|
||||
}
|
||||
public class func warn(_ message: String) {
|
||||
instance.service.warning(message: message)
|
||||
}
|
||||
public class func error(_ message: String) {
|
||||
instance.service.error(message: message)
|
||||
}
|
||||
public class func fatal(_ message: String) {
|
||||
instance.service.fatal(message: message)
|
||||
}
|
||||
|
||||
private func output(_ message: String, _ level: Int, _ domain: String = Bundle.main.bundleIdentifier!) {
|
||||
let log = "[\(domain)][\(levelToStrings[level] ?? "Unkown")] \(message)\n"
|
||||
if #available(iOS 10.0, *) {
|
||||
os_log("%{public}@", type: levelToOSleLogLevel[level] ?? .info,log)
|
||||
} else {
|
||||
NSLog(log)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func onLogMessageWritten(logService: linphonesw.LoggingService, domain: String, level: linphonesw.LogLevel, message: String) {
|
||||
output(message, level.rawValue, domain)
|
||||
}
|
||||
|
||||
public class func stackTrace() {
|
||||
Thread.callStackSymbols.forEach{ print($0) }
|
||||
}
|
||||
|
||||
// Debug
|
||||
public class func cdlog(_ message: String) {
|
||||
info("cdes>\(message)")
|
||||
}
|
||||
public class func bmlog(_ message: String) {
|
||||
info("bmar>\(message)")
|
||||
}
|
||||
public class func qelog(_ message: String) {
|
||||
info("qarg>\(message)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// swiftlint:enable line_length
|
||||
Loading…
Add table
Reference in a new issue