From 864c22093b29779e20cde9092cde6045f9e2d319 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Tue, 17 Sep 2024 23:53:44 +0000 Subject: [PATCH] Uplift of #25613 (squashed) to beta --- .../App/iOS/Delegates/AppDelegate.swift | 3 ++ .../Settings/SettingsViewController.swift | 11 ------ .../Sources/BraveShared/DebugLogger.swift | 13 ++++--- ios/brave-ios/Sources/Growth/DAU.swift | 4 --- .../Growth/URP/AdAttributionReportData.swift | 4 --- .../Sources/Growth/URP/ReferralData.swift | 1 - .../Sources/Growth/URP/UrpService.swift | 10 ------ .../Growth/URP/UserReferralProgram.swift | 36 ++----------------- 8 files changed, 12 insertions(+), 70 deletions(-) diff --git a/ios/brave-ios/App/iOS/Delegates/AppDelegate.swift b/ios/brave-ios/App/iOS/Delegates/AppDelegate.swift index 30f4b2abea11..c68e560a8fe4 100644 --- a/ios/brave-ios/App/iOS/Delegates/AppDelegate.swift +++ b/ios/brave-ios/App/iOS/Delegates/AppDelegate.swift @@ -131,6 +131,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Clean Logger for Secure content state DebugLogger.cleanLogger(for: .secureState) + // Clean Logger for URP (no longer used) + DebugLogger.cleanUrpLogs() + return true } diff --git a/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift b/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift index e02fd873f334..46eae3c91d4e 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift @@ -1048,17 +1048,6 @@ class SettingsViewController: TableViewController { accessory: .disclosureIndicator, cellClass: MultilineValue1Cell.self ), - Row( - text: "View URP Logs", - selection: { [unowned self] in - self.navigationController?.pushViewController( - DebugLogViewController(type: .urp), - animated: true - ) - }, - accessory: .disclosureIndicator, - cellClass: MultilineValue1Cell.self - ), Row(text: "URP Code: \(UserReferralProgram.getReferralCode() ?? "--")"), Row( text: "BraveCore Switches", diff --git a/ios/brave-ios/Sources/BraveShared/DebugLogger.swift b/ios/brave-ios/Sources/BraveShared/DebugLogger.swift index 1d4771219575..33805681c8c9 100644 --- a/ios/brave-ios/Sources/BraveShared/DebugLogger.swift +++ b/ios/brave-ios/Sources/BraveShared/DebugLogger.swift @@ -8,12 +8,10 @@ import Shared import UIKit public enum LoggerType { - case urp, secureState + case secureState var prefsKey: String { switch self { - case .urp: - return "urpLogs" case .secureState: return "secureStateLogs" } @@ -49,8 +47,6 @@ public struct DebugLogger { case .secureState: logs.append("------------------------------------\n\n") logs.append(" [\(time)]\n\n \(text)\n") - case .urp: - logs.append("[\(time)] \(text)\n") } UserDefaults.standard.set(logs, forKey: type.prefsKey) @@ -59,6 +55,11 @@ public struct DebugLogger { public static func cleanLogger(for type: LoggerType) { UserDefaults.standard.removeObject(forKey: type.prefsKey) } + + public static func cleanUrpLogs() { + // Delete the no-longer used urp logs if they exist + UserDefaults.standard.removeObject(forKey: "urpLogs") + } } public class DebugLogViewController: UIViewController { @@ -78,8 +79,6 @@ public class DebugLogViewController: UIViewController { super.viewDidLoad() switch loggerType { - case .urp: - title = "URP Logs" case .secureState: title = "Secure Content State" } diff --git a/ios/brave-ios/Sources/Growth/DAU.swift b/ios/brave-ios/Sources/Growth/DAU.swift index e60258a5420f..f2db248b1579 100644 --- a/ios/brave-ios/Sources/Growth/DAU.swift +++ b/ios/brave-ios/Sources/Growth/DAU.swift @@ -101,7 +101,6 @@ public class DAU { @objc private func sendPingToServerInternal() { guard let paramsAndPrefs = paramsAndPrefsSetup(for: Date()) else { Logger.module.debug("dau, no changes detected, no server ping") - DebugLogger.log(for: .urp, text: "dau, no changes detected, no server ping") return } @@ -123,7 +122,6 @@ public class DAU { } Logger.module.debug("send ping to server, url: \(pingRequestUrl)") - DebugLogger.log(for: .urp, text: "send ping to server, url: \(pingRequestUrl)") var request = URLRequest(url: pingRequestUrl) for (key, value) in paramsAndPrefs.headers { @@ -137,7 +135,6 @@ public class DAU { if let e = error { Logger.module.error("status update error: \(e.localizedDescription)") - DebugLogger.log(for: .urp, text: "status update error: \(e)") return } @@ -224,7 +221,6 @@ public class DAU { if let referralCode = UserReferralProgram.getReferralCode() { params.append(URLQueryItem(name: "ref", value: referralCode)) - DebugLogger.log(for: .urp, text: "DAU ping with added ref, params: \(params)") } let lastPingTimestamp = [Int((date).timeIntervalSince1970)] diff --git a/ios/brave-ios/Sources/Growth/URP/AdAttributionReportData.swift b/ios/brave-ios/Sources/Growth/URP/AdAttributionReportData.swift index 4d5a4454f92f..e238f64581c2 100644 --- a/ios/brave-ios/Sources/Growth/URP/AdAttributionReportData.swift +++ b/ios/brave-ios/Sources/Growth/URP/AdAttributionReportData.swift @@ -67,15 +67,11 @@ public struct AdAttributionData { // They will indicate if the Apple Searhs Ads is clicked and for which campaign guard let attribution = json["attribution"] as? Bool else { Logger.module.error("Failed to unwrap json to Ad Attribution property.") - DebugLogger.log(for: .urp, text: "Failed to unwrap json to Ad Attribution property. \(json)") - throw SerializationError.missing("Attribution Context") } guard let campaignId = json["campaignId"] as? Int else { Logger.module.error("Failed to unwrap json to Campaign Id property.") - DebugLogger.log(for: .urp, text: "Failed to unwrap json to Campaign Id property. \(json)") - throw SerializationError.missing("Campaign Id") } diff --git a/ios/brave-ios/Sources/Growth/URP/ReferralData.swift b/ios/brave-ios/Sources/Growth/URP/ReferralData.swift index e4fbdc83040c..dbada9a3b8e9 100644 --- a/ios/brave-ios/Sources/Growth/URP/ReferralData.swift +++ b/ios/brave-ios/Sources/Growth/URP/ReferralData.swift @@ -29,7 +29,6 @@ struct ReferralData { guard let downloadId = json["download_id"].string, let code = json["referral_code"].string else { Logger.module.error("Failed to unwrap json to Referral struct.") - DebugLogger.log(for: .urp, text: "Failed to unwrap json to Referral struct. \(json)") return nil } diff --git a/ios/brave-ios/Sources/Growth/URP/UrpService.swift b/ios/brave-ios/Sources/Growth/URP/UrpService.swift index b19888785fa1..f805b7569992 100644 --- a/ios/brave-ios/Sources/Growth/URP/UrpService.swift +++ b/ios/brave-ios/Sources/Growth/URP/UrpService.swift @@ -53,7 +53,6 @@ struct UrpService { ) { guard var endPoint = URL(string: host) else { completion(nil, .endpointError) - DebugLogger.log(for: .urp, text: "Host not a url: \(host)") return } @@ -76,19 +75,12 @@ struct UrpService { ) } - DebugLogger.log(for: .urp, text: "Referral code lookup response: \(data)") - let json = JSON(data) let referral = ReferralData(json: json) completion(referral, nil) case .failure(let error): Logger.module.error("Referral code lookup response: \(error.localizedDescription)") - DebugLogger.log( - for: .urp, - text: "Referral code lookup response: \(error.localizedDescription)" - ) - completion(nil, .endpointError) } } @@ -113,7 +105,6 @@ struct UrpService { isRetryEnabled: isRetryEnabled, timeout: timeout ) - DebugLogger.log(for: .urp, text: "Ad Attribution response: \(result)") if let resultData = result as? Data { let jsonResponse = @@ -146,7 +137,6 @@ struct UrpService { do { let (result, _) = try await sessionManager.adGroupsReportApiRequest(endPoint: endPoint) - DebugLogger.log(for: .urp, text: "Ad Groups Report response: \(result)") if let resultData = result as? Data { let adGroupsReportData = try AdGroupReportData(data: resultData, keywordId: keywordId) diff --git a/ios/brave-ios/Sources/Growth/URP/UserReferralProgram.swift b/ios/brave-ios/Sources/Growth/URP/UserReferralProgram.swift index 27e1a31f4368..6368df3467bb 100644 --- a/ios/brave-ios/Sources/Growth/URP/UserReferralProgram.swift +++ b/ios/brave-ios/Sources/Growth/URP/UserReferralProgram.swift @@ -51,8 +51,6 @@ public class UserReferralProgram { adReportsURL: adReportsURLString ) - DebugLogger.log(for: .urp, text: "URP init, host: \(host)") - self.service = urpService } @@ -61,16 +59,10 @@ public class UserReferralProgram { refCode: String? = nil, completion: @escaping (_ refCode: String?, _ offerUrl: String?) -> Void ) { - DebugLogger.log(for: .urp, text: "first run referral lookup") - let referralBlock: (ReferralData?, UrpError?) -> Void = { [weak self] referral, error in guard let self = self else { return } if error == Growth.UrpError.endpointError { - DebugLogger.log( - for: .urp, - text: "URP look up had endpoint error, will retry on next launch." - ) self.referralLookupRetry.timer?.invalidate() self.referralLookupRetry.timer = nil @@ -95,17 +87,12 @@ public class UserReferralProgram { Preferences.URP.referralLookupOutstanding.value = false guard let ref = referral else { Logger.module.info("No referral code found") - DebugLogger.log(for: .urp, text: "No referral code found") completion(nil, nil) return } if ref.isExtendedUrp() { completion(ref.referralCode, ref.offerPage) - DebugLogger.log( - for: .urp, - text: "Extended referral code found, opening landing page: \(ref.offerPage ?? "404")" - ) // We do not want to persist referral data for extended URPs return } @@ -116,10 +103,6 @@ public class UserReferralProgram { self.referralLookupRetry.timer?.invalidate() self.referralLookupRetry.timer = nil - DebugLogger.log( - for: .urp, - text: "Found referral: downloadId: \(ref.downloadId), code: \(ref.referralCode)" - ) // In case of network errors or getting `isFinalized = false`, we retry the api call. self.initRetryPingConnection(numberOfTimes: 30) @@ -192,13 +175,12 @@ public class UserReferralProgram { public func pingIfEnoughTimePassed() { if !DeviceInfo.hasConnectivity() { - DebugLogger.log(for: .urp, text: "No internet connection, not sending update ping.") + Logger.module.info("No internet connection, not sending update ping.") return } guard let downloadId = Preferences.URP.downloadId.value else { Logger.module.info("Could not retrieve download id model from preferences.") - DebugLogger.log(for: .urp, text: "Update ping, no download id found.") return } @@ -211,11 +193,9 @@ public class UserReferralProgram { if todayInSeconds <= checkDate { Logger.module.debug("Not enough time has passed for referral ping.") - DebugLogger.log(for: .urp, text: "Not enough time has passed for referral ping.") return } - DebugLogger.log(for: .urp, text: "Update ping") service.checkIfAuthorizedForGrant(with: downloadId) { initialized, error in guard let counter = Preferences.URP.retryCountdown.value else { Logger.module.error("Could not retrieve retry countdown from preferences.") @@ -225,33 +205,23 @@ public class UserReferralProgram { var shouldRemoveData = false if error == .downloadIdNotFound { - DebugLogger.log(for: .urp, text: "Download id not found on server.") shouldRemoveData = true } if initialized == true { - DebugLogger.log(for: .urp, text: "Got initialized = true from server.") shouldRemoveData = true } // Last retry attempt if counter <= 1 { - DebugLogger.log(for: .urp, text: "Last retry and failed to get data from server.") shouldRemoveData = true } if shouldRemoveData { - DebugLogger.log(for: .urp, text: "Removing all referral data from device") - Preferences.URP.downloadId.value = nil Preferences.URP.nextCheckDate.value = nil Preferences.URP.retryCountdown.value = nil } else { - DebugLogger.log( - for: .urp, - text: - "Network error or isFinalized returned false, decrementing retry counter and trying again next time." - ) // Decrement counter, next retry happens on next day Preferences.URP.retryCountdown.value = counter - 1 Preferences.URP.nextCheckDate.value = checkDate + 1.days @@ -266,13 +236,13 @@ public class UserReferralProgram { { Preferences.URP.referralCode.value = nil Preferences.URP.referralCodeDeleteDate.value = nil - DebugLogger.log(for: .urp, text: "Enough time has passed, removing referral code data") + Logger.module.info("Enough time has passed, removing referral code data") return nil } else if let referralCode = Preferences.URP.referralCode.value { // Appending ref code to dau ping if user used installed the app via // user referral program or apple search ad if Preferences.URP.referralCodeDeleteDate.value == nil { - DebugLogger.log(for: .urp, text: "Setting new date for deleting referral code.") + Logger.module.info("Setting new date for deleting referral code.") let timeToDelete = AppConstants.isOfficialBuild ? 90.days : 20.minutes Preferences.URP.referralCodeDeleteDate.value = Date().timeIntervalSince1970 + timeToDelete }