-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App: UISI AutoReporting #5743
Merged
Merged
App: UISI AutoReporting #5743
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f1ad14d
Add UISIDetector
langleyd 2309908
Add AutoReported, re-work big client interface and hook up AutoReporter.
langleyd 5c39eb2
Update detector to match web implementation(only track decryption att…
langleyd 4e1e9af
Merge branch 'develop' of github.com:vector-im/element-ios into langl…
langleyd 0251a01
fix merge
langleyd cff98cd
Revert "fix merge"
langleyd fc9e4a9
Actually fix merge.
langleyd e031cb5
Fix documentation and update big report client init.
langleyd 18ca901
cleanup marks and make a couple of functions private.
langleyd 5a5e77f
Add matchingIssue to sender report and fix description, was missing "…
langleyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Encodable { | ||
/// Convenience method to get the json string of an Encodable | ||
var jsonString: String? { | ||
let encoder = JSONEncoder() | ||
guard let jsonData = try? encoder.encode(self) else { return nil } | ||
return String(data: jsonData, encoding: .utf8) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import MatrixSDK | ||
import GBDeviceInfo | ||
|
||
extension MXBugReportRestClient { | ||
|
||
@objc static func vc_bugReportRestClient(appName: String) -> MXBugReportRestClient { | ||
let client = MXBugReportRestClient(bugReportEndpoint: BuildSettings.bugReportEndpointUrlString) | ||
// App info | ||
client.appName = appName | ||
client.version = AppDelegate.theDelegate().appVersion | ||
client.build = AppDelegate.theDelegate().build | ||
|
||
client.deviceModel = GBDeviceInfo.deviceInfo().modelString | ||
client.deviceOS = "\(UIDevice.current.systemName) \(UIDevice.current.systemVersion)" | ||
return client | ||
} | ||
|
||
@objc func vc_sendBugReport( | ||
description: String, | ||
sendLogs: Bool, | ||
sendCrashLog: Bool, | ||
sendFiles: [URL]? = nil, | ||
additionalLabels: [String]? = nil, | ||
customFields: [String: String]? = nil, | ||
progress: ((MXBugReportState, Progress?) -> Void)? = nil, | ||
success: ((String?) -> Void)? = nil, | ||
failure: ((Error?) -> Void)? = nil | ||
) { | ||
// User info (TODO: handle multi-account and find a way to expose them in rageshake API) | ||
var userInfo = [String: String]() | ||
let mainAccount = MXKAccountManager.shared().accounts.first | ||
if let userId = mainAccount?.mxSession.myUser.userId { | ||
userInfo["user_id"] = userId | ||
} | ||
if let deviceId = mainAccount?.mxSession.matrixRestClient.credentials.deviceId { | ||
userInfo["device_id"] = deviceId | ||
} | ||
|
||
userInfo["locale"] = NSLocale.preferredLanguages[0] | ||
userInfo["default_app_language"] = Bundle.main.preferredLocalizations[0] // The language chosen by the OS | ||
userInfo["app_language"] = Bundle.mxk_language() ?? userInfo["default_app_language"] // The language chosen by the user | ||
|
||
// Application settings | ||
userInfo["lazy_loading"] = MXKAppSettings.standard().syncWithLazyLoadOfRoomMembers ? "ON" : "OFF" | ||
|
||
let currentDate = Date() | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
userInfo["local_time"] = dateFormatter.string(from: currentDate) | ||
|
||
dateFormatter.timeZone = TimeZone(identifier: "UTC") | ||
userInfo["utc_time"] = dateFormatter.string(from: currentDate) | ||
|
||
if let customFields = customFields { | ||
// combine userInfo with custom fields overriding with custom where there is a conflict | ||
userInfo.merge(customFields) { (_, new) in new } | ||
} | ||
others = userInfo | ||
|
||
var labels: [String] = additionalLabels ?? [String]() | ||
// Add a Github label giving information about the version | ||
if var versionLabel = version, let buildLabel = build { | ||
|
||
// If this is not the app store version, be more accurate on the build origin | ||
if buildLabel == VectorL10n.settingsConfigNoBuildInfo { | ||
// This is a debug session from Xcode | ||
versionLabel += "-debug" | ||
} else if !buildLabel.contains("master") { | ||
// This is a Jenkins build. Add the branch and the build number | ||
let buildString = buildLabel.replacingOccurrences(of: " ", with: "-") | ||
versionLabel += "-\(buildString)" | ||
} | ||
labels += [versionLabel] | ||
} | ||
if sendCrashLog { | ||
labels += ["crash"] | ||
} | ||
|
||
var sendDescription = description | ||
if sendCrashLog, | ||
let crashLogFile = MXLogger.crashLog(), | ||
let crashLog = try? String(contentsOfFile: crashLogFile, encoding: .utf8) { | ||
// Append the crash dump to the user description in order to ease triaging of GH issues | ||
sendDescription += "\n\n\n--------------------------------------------------------------------------------\n\n\(crashLog)" | ||
} | ||
|
||
sendBugReport(sendDescription, | ||
sendLogs: sendLogs, | ||
sendCrashLog: sendCrashLog, | ||
sendFiles: sendFiles, | ||
attachGitHubLabels: labels, | ||
progress: progress, | ||
success: success, | ||
failure: failure) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Combine | ||
|
||
@available(iOS 14.0, *) | ||
extension Publisher { | ||
|
||
/// | ||
/// Buffer upstream items and guarantee a time interval spacing out the published items. | ||
/// - Parameters: | ||
/// - spacingDelay: A delay in seconds to guarantee between emissions | ||
/// - scheduler: The `DispatchQueue` on which to schedule emissions. | ||
/// - Returns: The new wrapped publisher | ||
func bufferAndSpace(spacingDelay: Int, scheduler: DispatchQueue = DispatchQueue.main) -> Publishers.FlatMap< | ||
Publishers.SetFailureType<Publishers.Delay<Just<Publishers.Buffer<Self>.Output>, DispatchQueue>, Publishers.Buffer<Self>.Failure>, | ||
Publishers.Buffer<Self> | ||
> { | ||
return buffer(size: .max, prefetch: .byRequest, whenFull: .dropNewest) | ||
.flatMap(maxPublishers: .max(1)) { | ||
Just($0).delay(for: .seconds(spacingDelay), scheduler: scheduler) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
extension RiotSettings { | ||
|
||
@available(iOS 13.0, *) | ||
func publisher(for key: String) -> AnyPublisher<Notification, Never> { | ||
return NotificationCenter.default.publisher(for: .userDefaultValueUpdated) | ||
.filter({ $0.object as? String == key }) | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pixlwave I extracted the common common code for sending reports from the app in case it's useful for your needs.