Skip to content

Commit

Permalink
Merge branch 'release/7.90.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Sep 18, 2023
2 parents 525afda + 02a9f5e commit ea8b782
Show file tree
Hide file tree
Showing 26 changed files with 1,252 additions and 296 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,21 @@ jobs:
APPLE_API_KEY_ISSUER: ${{ secrets.APPLE_API_KEY_ISSUER }}
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
run: |
bundle exec fastlane release_${{ steps.destination.outputs.destination }}
app_version="$(cut -d ' ' -f 3 < Configuration/Version.xcconfig)"
echo "dsyms_path=${{ github.workspace }}/DuckDuckGo.app.dSYM.zip" >> $GITHUB_ENV
echo "app_version=${app_version}" >> $GITHUB_ENV
bundle exec fastlane release_${{ steps.destination.outputs.destination }}
- name: Upload dSYMs artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: DuckDuckGo-${{ steps.destination.outputs.destination }}-dSYM-${{ env.app_version }}
path: ${{ env.dsyms_path }}

- name: Get Asana Task ID
id: get-task-id
if: github.event.inputs.asana-task-url
if: ${{ always() && github.event.inputs.asana-task-url }}
run: |
task_url_regex='^https://app.asana.com/[0-9]/[0-9]*/([0-9]*)/f$'
if [[ "${{ github.event.inputs.asana-task-url }}" =~ ${task_url_regex} ]]; then
Expand All @@ -96,16 +97,18 @@ jobs:
fi
- name: Upload debug symbols to Asana
if: github.event.inputs.asana-task-url
if: ${{ always() && github.event.inputs.asana-task-url }}
env:
ASANA_ACCESS_TOKEN: ${{ secrets.ASANA_ACCESS_TOKEN }}
run: |
asana_dsyms_path="${{ github.workspace }}/DuckDuckGo-${{ env.app_version }}-dSYM.zip"
mv -f "${{ env.dsyms_path }}" "$asana_dsyms_path"
if [[ -f ${{ env.dsyms_path }} ]]; then
asana_dsyms_path="${{ github.workspace }}/DuckDuckGo-${{ env.app_version }}-dSYM.zip"
mv -f "${{ env.dsyms_path }}" "$asana_dsyms_path"
curl -s "https://app.asana.com/api/1.0/tasks/${{ steps.get-task-id.outputs.task_id }}/attachments" \
-H "Authorization: Bearer ${{ secrets.ASANA_ACCESS_TOKEN }}" \
--form "file=@${asana_dsyms_path};type=application/zip"
curl -s "https://app.asana.com/api/1.0/tasks/${{ steps.get-task-id.outputs.task_id }}/attachments" \
-H "Authorization: Bearer ${{ secrets.ASANA_ACCESS_TOKEN }}" \
--form "file=@${asana_dsyms_path};type=application/zip"
fi
- name: Send Mattermost message
env:
Expand Down
2 changes: 1 addition & 1 deletion Configuration/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MARKETING_VERSION = 7.89.0
MARKETING_VERSION = 7.90.0
4 changes: 2 additions & 2 deletions Core/AppPrivacyConfigurationDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import BrowserServicesKit
final public class AppPrivacyConfigurationDataProvider: EmbeddedDataProvider {

public struct Constants {
public static let embeddedDataETag = "\"357f365c05692d9674849261a9a91f71\""
public static let embeddedDataSHA = "cfa6f910f8d50b88d44a149f0e007bc8fd88b8b3b390ae013618599794d2c077"
public static let embeddedDataETag = "\"18cf17e7f3383d2f9d1f0f6643c90c04\""
public static let embeddedDataSHA = "3f37f6c999e2d358a343c9150b6f1ac3120931c027a173aa99dae571c2398f37"
}

public var embeddedDataEtag: String {
Expand Down
48 changes: 38 additions & 10 deletions Core/DefaultVariantManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,32 @@ public struct VariantIOS: Variant {
return false
}
}


/// This variant is used for returning users to separate them from really new users.
static let returningUser = VariantIOS(name: "ru", weight: doNotAllocate, isIncluded: When.always, features: [])

static let doNotAllocate = 0

// Note: Variants with `doNotAllocate` weight, should always be included so that previous installations are unaffected

/// The list of cohorts in active ATB experiments.
///
/// Variants set to `doNotAllocate` are active, but not adding users to a new cohort, do not change them unless you're sure the experiment is finished.
public static let defaultVariants: [Variant] = [
// SERP testing
VariantIOS(name: "sc", weight: doNotAllocate, isIncluded: When.always, features: []),
VariantIOS(name: "sd", weight: doNotAllocate, isIncluded: When.always, features: []),
VariantIOS(name: "se", weight: doNotAllocate, isIncluded: When.always, features: [])

VariantIOS(name: "se", weight: doNotAllocate, isIncluded: When.always, features: []),
returningUser
]


/// The name of the variant. Shuld be a two character string like `ma` or `mb`
public var name: String

/// The relative weight of this variant, e.g. if two variants have the same weight they will get 50% of the cohorts each.
public var weight: Int

/// Function to determine inclusion, e.g. if you want to only run an experiment on English users use `When.inEnglish`
public var isIncluded: () -> Bool

/// The experimental feature(s) being tested.
public var features: [FeatureName]

}
Expand All @@ -81,13 +92,26 @@ public class DefaultVariantManager: VariantManager {
private let variants: [Variant]
private let storage: StatisticsStore
private let rng: VariantRNG
private let returningUserMeasurement: ReturnUserMeasurement

public init(variants: [Variant] = VariantIOS.defaultVariants,
storage: StatisticsStore = StatisticsUserDefaults(),
rng: VariantRNG = Arc4RandomUniformVariantRNG()) {
init(variants: [Variant],
storage: StatisticsStore,
rng: VariantRNG,
returningUserMeasurement: ReturnUserMeasurement) {

self.variants = variants
self.storage = storage
self.rng = rng
self.returningUserMeasurement = returningUserMeasurement
}

public convenience init() {
self.init(
variants: VariantIOS.defaultVariants,
storage: StatisticsUserDefaults(),
rng: Arc4RandomUniformVariantRNG(),
returningUserMeasurement: KeychainReturnUserMeasurement()
)
}

public func isSupported(feature: FeatureName) -> Bool {
Expand Down Expand Up @@ -118,6 +142,10 @@ public class DefaultVariantManager: VariantManager {
}

private func selectVariant() -> Variant? {
if returningUserMeasurement.isReturningUser {
return VariantIOS.returningUser
}

let totalWeight = variants.reduce(0, { $0 + $1.weight })
let randomPercent = rng.nextInt(upperBound: totalWeight)

Expand Down
5 changes: 5 additions & 0 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public struct PixelParameters {
public static let sheetResult = "success"

public static let defaultBrowser = "default_browser"

// Return user
public static let returnUserErrorCode = "error_code"
public static let returnUserOldATB = "old_atb"
public static let returnUserNewATB = "new_atb"
}

public struct PixelValues {
Expand Down
20 changes: 19 additions & 1 deletion Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ extension Pixel {
case onboardingSetDefaultOpened
case onboardingSetDefaultSkipped

// MARK: Return user measurement
case returnUser

// MARK: debug pixels
case dbCrashDetected

Expand Down Expand Up @@ -392,7 +395,12 @@ extension Pixel {
case debugCantSaveBookmarkFix

case debugCannotClearObservationsDatabase


// Return user measurement
case debugReturnUserReadATB
case debugReturnUserAddATB
case debugReturnUserUpdateATB

// Errors from Bookmarks Module
case bookmarkFolderExpected
case bookmarksListIndexNotMatchingBookmark
Expand Down Expand Up @@ -445,6 +453,8 @@ extension Pixel {
case emailIncontextModalDismissed
case emailIncontextModalExitEarly
case emailIncontextModalExitEarlyContinue

case incrementalRolloutTest
}

}
Expand Down Expand Up @@ -881,6 +891,14 @@ extension Pixel.Event {
case .emailIncontextModalDismissed: return "m_email_incontext_modal_dismissed"
case .emailIncontextModalExitEarly: return "m_email_incontext_modal_exit_early"
case .emailIncontextModalExitEarlyContinue: return "m_email_incontext_modal_exit_early_continue"

// MARK: - Return user measurement
case .returnUser: return "m_return_user"
case .debugReturnUserAddATB: return "m_debug_return_user_add_atb"
case .debugReturnUserReadATB: return "m_debug_return_user_read_atb"
case .debugReturnUserUpdateATB: return "m_debug_return_user_update_atb"

case .incrementalRolloutTest: return "m_autofill_incremental_rollout_test"
}

}
Expand Down
150 changes: 150 additions & 0 deletions Core/ReturnUserMeasurement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//
// ReturnUserMeasurement.swift
// DuckDuckGo
//
// Copyright © 2023 DuckDuckGo. All rights reserved.
//
// 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 BrowserServicesKit

protocol ReturnUserMeasurement {

var isReturningUser: Bool { get }
func installCompletedWithATB(_ atb: Atb)
func updateStoredATB(_ atb: Atb)

}

class KeychainReturnUserMeasurement: ReturnUserMeasurement {

static let SecureATBKeychainName = "returning-user-atb"

struct Measurement {

let oldATB: String?
let newATB: String

}

/// Called from the `VariantManager` to determine which variant to use
var isReturningUser: Bool {
return hasAnyKeychainItems()
}

func installCompletedWithATB(_ atb: Atb) {
if let oldATB = readSecureATB() {
sendReturnUserMeasurement(oldATB, atb.version)
}
writeSecureATB(atb.version)
}

/// Update the stored ATB with an even more generalised version of the ATB, if present.
func updateStoredATB(_ atb: Atb) {
guard let atb = atb.updateVersion else { return }
writeSecureATB(atb)
}

private func writeSecureATB(_ atb: String) {
let data = atb.data(using: .utf8)!

var query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: Self.SecureATBKeychainName,
kSecValueData as String: data,

// We expect to only need access when the app is in the foreground and we want it to be migrated to new devices.
kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlocked,

// Just to be explicit that we don't want this stored in the cloud
kSecAttrSynchronizable as String: false
]

var status = SecItemAdd(query as CFDictionary, nil)
if status == errSecDuplicateItem {
let attributesToUpdate: [String: Any] = [
kSecValueData as String: data
]
query.removeValue(forKey: kSecValueData as String)
status = SecItemUpdate(query as CFDictionary, attributesToUpdate as CFDictionary)
if status != errSecSuccess {
fireDebugPixel(.debugReturnUserUpdateATB, errorCode: status)
}
} else if status != errSecSuccess {
fireDebugPixel(.debugReturnUserAddATB, errorCode: status)
}

}

private func readSecureATB() -> String? {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: Self.SecureATBKeychainName,
kSecReturnData as String: kCFBooleanTrue!,
kSecMatchLimit as String: kSecMatchLimitOne
]

var dataTypeRef: AnyObject?
let status: OSStatus = SecItemCopyMatching(query as CFDictionary, &dataTypeRef)
if ![errSecSuccess, errSecItemNotFound].contains(status) {
fireDebugPixel(.debugReturnUserReadATB, errorCode: status)
}

if let data = dataTypeRef as? Data {
return String(data: data, encoding: .utf8)
}

return nil
}

private func sendReturnUserMeasurement(_ oldATB: String, _ newATB: String) {
Pixel.fire(pixel: .returnUser, withAdditionalParameters: [
PixelParameters.returnUserOldATB: oldATB,
PixelParameters.returnUserNewATB: newATB
])
}

private func fireDebugPixel(_ event: Pixel.Event, errorCode: OSStatus) {
Pixel.fire(pixel: event, withAdditionalParameters: [
PixelParameters.returnUserErrorCode: "\(errorCode)"
])
}

/// Only check for keychain items created by *this* app.
private func hasAnyKeychainItems() -> Bool {
let possibleStorageClasses = [
kSecClassGenericPassword,
kSecClassKey
]
return possibleStorageClasses.first(where: hasKeychainItemsInClass(_:)) != nil
}

private func hasKeychainItemsInClass(_ secClassCFString: CFString) -> Bool {
let query: [String: Any] = [
kSecClass as String: secClassCFString,
kSecMatchLimit as String: kSecMatchLimitOne,
kSecReturnAttributes as String: true, // Needs to be true or returns nothing.
kSecReturnRef as String: true,
]
var returnArrayRef: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &returnArrayRef)
guard status == errSecSuccess,
let returnArray = returnArrayRef as? [String: Any] else {
return false
}
return returnArray.count > 0
}

}
7 changes: 6 additions & 1 deletion Core/StatisticsLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public class StatisticsLoader {
public static let shared = StatisticsLoader()

private let statisticsStore: StatisticsStore
private let returnUserMeasurement: ReturnUserMeasurement
private let parser = AtbParser()

init(statisticsStore: StatisticsStore = StatisticsUserDefaults()) {
init(statisticsStore: StatisticsStore = StatisticsUserDefaults(),
returnUserMeasurement: ReturnUserMeasurement = KeychainReturnUserMeasurement()) {
self.statisticsStore = statisticsStore
self.returnUserMeasurement = returnUserMeasurement
}

public func load(completion: @escaping Completion = {}) {
Expand Down Expand Up @@ -77,6 +80,7 @@ public class StatisticsLoader {
}
self.statisticsStore.installDate = Date()
self.statisticsStore.atb = atb.version
self.returnUserMeasurement.installCompletedWithATB(atb)
completion()
}
}
Expand Down Expand Up @@ -134,6 +138,7 @@ public class StatisticsLoader {
public func storeUpdateVersionIfPresent(_ atb: Atb) {
if let updateVersion = atb.updateVersion {
statisticsStore.atb = updateVersion
returnUserMeasurement.updateStoredATB(atb)
}
}
}
2 changes: 2 additions & 0 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public struct UserDefaultsWrapper<T> {
case appTPUsed = "com.duckduckgo.ios.appTrackingProtection.appTPUsed"

case defaultBrowserUsageLastSeen = "com.duckduckgo.ios.default-browser-usage-last-seen"

case syncEnvironment = "com.duckduckgo.ios.sync-environment"
}

private let key: Key
Expand Down
Loading

0 comments on commit ea8b782

Please sign in to comment.