Skip to content

Commit 04ec622

Browse files
author
Matt Buckley
authored
Revert "Chaff Requests Implementation (iOS) (#891)" (#905)
This reverts commit 6d7dc48.
1 parent 064c5c6 commit 04ec622

File tree

9 files changed

+17
-183
lines changed

9 files changed

+17
-183
lines changed

ios/AppDelegate.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5555

5656
[ExposureManager createSharedInstance];
5757
[[ExposureManager shared] registerExposureDetectionBackgroundTask];
58-
[[ExposureManager shared] registerChaffBackgroundTask];
5958
[[ExposureManager shared] registerDeleteOldExposuresBackgroundTask];
6059

6160
[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView];

ios/BT/ExposureManager.swift

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ enum ENAPIVersion { case V1, V2 }
3636

3737
@objc(ExposureManager)
3838
/**
39-
This class wrapps [ENManager](https://developer.apple.com/documentation/exposurenotification/enmanager) and acts like a controller and entry point of the different flows
39+
This class wraps [ENManager](https://developer.apple.com/documentation/exposurenotification/enmanager) and acts like a controller and entry point of the different flows
4040
*/
4141

4242
final class ExposureManager: NSObject {
4343

44-
private static let backgroundTaskIdentifier = "\(Bundle.main.bundleIdentifier!).exposure-notification"
45-
private static let chaffBackgroundTaskIdentifier = "\(Bundle.main.bundleIdentifier!).chaff"
44+
private static let exposureDetectionBackgroundTaskIdentifier = "\(Bundle.main.bundleIdentifier!).exposure-notification"
4645
private static let deleteOldExposuresBackgroundTaskIdentifier = "\(Bundle.main.bundleIdentifier!).delete-old-exposures"
4746

4847
@objc private(set) static var shared: ExposureManager?
@@ -86,20 +85,13 @@ final class ExposureManager: NSObject {
8685
self?.activateSuccess()
8786
}
8887
}
89-
// Schedule background tasks if needed whenever EN authorization status changes
88+
// Schedule background task if needed whenever EN authorization status changes
9089
notificationCenter.addObserver(
9190
self,
9291
selector: #selector(scheduleExposureDetectionBackgroundTaskIfNeeded),
9392
name: .ExposureNotificationStatusDidChange,
9493
object: nil
9594
)
96-
97-
notificationCenter.addObserver(
98-
self,
99-
selector: #selector(scheduleChaffBackgroundTaskIfNeeded),
100-
name: .ChaffRequestTriggered,
101-
object: nil
102-
)
10395
}
10496

10597
deinit {
@@ -216,12 +208,6 @@ final class ExposureManager: NSObject {
216208
}, callback: callback)
217209
}
218210

219-
@objc func fetchChaffKeys(callback: @escaping (ExposureKeysDictionaryArray?, ExposureManagerError?) -> Void) {
220-
getDiagnosisKeys(transform: { (keys) -> ExposureKeysDictionaryArray in
221-
(keys ?? []).map { $0.chaffRepresentation }
222-
}, callback: callback)
223-
}
224-
225211

226212
// MARK: == Exposure Detection ==
227213

@@ -230,7 +216,7 @@ final class ExposureManager: NSObject {
230216
All launch handlers must be registered before application finishes launching
231217
*/
232218
@objc func registerExposureDetectionBackgroundTask() {
233-
bgTaskScheduler.register(forTaskWithIdentifier: ExposureManager.backgroundTaskIdentifier,
219+
bgTaskScheduler.register(forTaskWithIdentifier: ExposureManager.exposureDetectionBackgroundTaskIdentifier,
234220
using: .main) { [weak self] task in
235221
guard let strongSelf = self else { return }
236222
// Notify the user if bluetooth is off
@@ -256,27 +242,7 @@ final class ExposureManager: NSObject {
256242
self?.scheduleExposureDetectionBackgroundTaskIfNeeded()
257243
}
258244
}
259-
260-
/**
261-
Registers the background task of sending chaff requests
262-
All launch handlers must be registered before application finishes launching
263-
*/
264-
@objc func registerChaffBackgroundTask() {
265-
bgTaskScheduler.register(forTaskWithIdentifier: ExposureManager.chaffBackgroundTaskIdentifier,
266-
using: .main) { [weak self] task in
267-
268-
// Perform the chaff request
269-
let currentHour = Calendar.current.dateComponents([.hour], from: Date()).hour ?? 0
270-
271-
if (currentHour > 8 && currentHour < 19) {
272-
self?.performChaffRequest()
273-
}
274-
275-
// Schedule the next background task
276-
self?.scheduleChaffBackgroundTaskIfNeeded()
277-
}
278-
}
279-
245+
280246
/**
281247
Registers the background task of deleting exposures > 14 days old
282248
from the local database
@@ -294,18 +260,7 @@ final class ExposureManager: NSObject {
294260

295261
@objc func scheduleExposureDetectionBackgroundTaskIfNeeded() {
296262
guard manager.exposureNotificationStatus == .active else { return }
297-
let taskRequest = BGProcessingTaskRequest(identifier: ExposureManager.backgroundTaskIdentifier)
298-
taskRequest.requiresNetworkConnectivity = true
299-
do {
300-
try bgTaskScheduler.submit(taskRequest)
301-
} catch {
302-
print("Unable to schedule background task: \(error)")
303-
}
304-
}
305-
306-
@objc func scheduleChaffBackgroundTaskIfNeeded() {
307-
guard manager.exposureNotificationStatus == .active else { return }
308-
let taskRequest = BGProcessingTaskRequest(identifier: ExposureManager.chaffBackgroundTaskIdentifier)
263+
let taskRequest = BGProcessingTaskRequest(identifier: ExposureManager.exposureDetectionBackgroundTaskIdentifier)
309264
taskRequest.requiresNetworkConnectivity = true
310265
do {
311266
try bgTaskScheduler.submit(taskRequest)
@@ -661,18 +616,6 @@ private extension ExposureManager {
661616
))
662617
}
663618

664-
func performChaffRequest() {
665-
fetchChaffKeys { [weak self] (keyArray, error) in
666-
if error != nil {
667-
print("error: \(error.debugDescription)")
668-
}
669-
self?.notificationCenter.post(Notification(
670-
name: .ChaffRequestTriggered,
671-
object: keyArray
672-
))
673-
}
674-
}
675-
676619
func getDiagnosisKeys<T>(transform: @escaping ([ENTemporaryExposureKey]?) -> T,
677620
callback: @escaping (T?, ExposureManagerError?) -> Void) {
678621
manager.getDiagnosisKeys { (keys, error) in

ios/BT/Extensions/Exposure Notifications/ENTemporaryExposureKey+Extensions.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ extension ENTemporaryExposureKey {
1919
]
2020
}
2121

22-
var chaffRepresentation : [String: Any] {
23-
return [
24-
"key": keyData.base64EncodedString().shuffled(),
25-
"rollingPeriod": rollingPeriod,
26-
"rollingStartNumber": rollingStartNumber,
27-
"transmissionRisk": transmissionRiskLevel
28-
]
29-
}
30-
3122
static func rollingStartNumber(_ date: Date) -> UInt32 {
3223
UInt32(Int(date.timeIntervalSince1970 / (24 * 60 * 60)) * Constants.intervalsPerRollingPeriod)
3324
}

ios/BT/Extensions/Foundation/Notification+Extensions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extension Notification.Name {
77
public static let HMACKeyDidChange = Notification.Name(rawValue: "BTSecureStorageHMACKeyDidChange")
88
public static let revisionTokenDidChange = Notification.Name(rawValue: "onRevisionTokenDidChange")
99
public static let ExposuresDidChange = Notification.Name(rawValue: "onExposureRecordUpdated")
10-
public static let ChaffRequestTriggered = Notification.Name(rawValue: "onChaffRequestTriggered")
1110
public static let ExposureNotificationStatusDidChange = Notification.Name(rawValue: "onEnabledStatusUpdated")
1211
public static let remainingDailyFileProcessingCapacityDidChange = Notification.Name(rawValue: "remainingDailyFileProcessingCapacityDidChange")
1312
public static let UrlOfMostRecentlyDetectedKeyFileDidChange = Notification.Name(rawValue: "UrlOfMostRecentlyDetectedKeyFileDidChange")

ios/BT/bridge/ExposureEventEmitter.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#import <React/RCTEventEmitter.h>
33

44
// Notification/Event Names
5-
NSString *const onChaffRequestTriggered = @"onChaffRequestTriggered";
65
NSString *const onEnabledStatusUpdated = @"onEnabledStatusUpdated";
76
NSString *const onExposuresChanged = @"onExposureRecordUpdated";
87

@@ -32,7 +31,6 @@ - (instancetype)init
3231
return @[
3332
onExposuresChanged,
3433
onEnabledStatusUpdated,
35-
onChaffRequestTriggered
3634
];
3735
}
3836

ios/COVIDSafePathsTests/ExposureManagerUnitTests.swift

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,14 @@ class ExposureManagerUnitTests: XCTestCase {
289289
let activateExpectation = self.expectation(description: "Activate gets called")
290290
let invalidateExpectation = self.expectation(description: "Invalidate gets called")
291291

292-
let registerExposureNotificationsStatusNotificationExpectation = self.expectation(description: "Registers for authorization changes")
293-
let registerChaffRequestNotificationExpectation = self.expectation(description: "Registers for chaff request notifications")
294-
292+
let registerNotificationExpectation = self.expectation(description: "Registers for authorization changes")
293+
295294
let setExposureNotificationEnabledTrueExpectation = self.expectation(description: "When activated, if disabled, request to enable exposure notifications")
296295

297296
let notificationCenterMock = NotificationCenterMock()
298297
notificationCenterMock.addObserverHandler = { (_, _, name, _) in
299298
if name == Notification.Name.ExposureNotificationStatusDidChange {
300-
registerExposureNotificationsStatusNotificationExpectation.fulfill()
301-
}
302-
if name == Notification.Name.ChaffRequestTriggered {
303-
registerChaffRequestNotificationExpectation.fulfill()
299+
registerNotificationExpectation.fulfill()
304300
}
305301
}
306302

@@ -327,8 +323,7 @@ class ExposureManagerUnitTests: XCTestCase {
327323
notificationCenter: notificationCenterMock)
328324
wait(for: [activateExpectation,
329325
invalidateExpectation,
330-
registerExposureNotificationsStatusNotificationExpectation,
331-
registerChaffRequestNotificationExpectation,
326+
registerNotificationExpectation,
332327
setExposureNotificationEnabledTrueExpectation], timeout: 1)
333328
}
334329

@@ -497,7 +492,7 @@ class ExposureManagerUnitTests: XCTestCase {
497492
wait(for: [addNotificatiionRequestExpectation, removeNotificationsExpectation], timeout: 0)
498493
}
499494

500-
func testRegisterExposureDetectionBackgroundTask() {
495+
func testregisterExposureDetectionBackgroundTask() {
501496
let registerExpectation = self.expectation(description: "A background task with the given identifier is registered")
502497
let bgSchedulerMock = BGTaskSchedulerMock()
503498
bgSchedulerMock.registerHandler = { identifier, launchHanlder in
@@ -509,7 +504,7 @@ class ExposureManagerUnitTests: XCTestCase {
509504
wait(for: [registerExpectation], timeout: 0)
510505
}
511506

512-
func testSubmitExposureDetectionBackgroundTask() {
507+
func testSubmitBackgroundTask() {
513508
let mockEnManager = ENManagerMock()
514509
mockEnManager.exposureNotificationStatusHandler = {
515510
return .active
@@ -525,34 +520,6 @@ class ExposureManagerUnitTests: XCTestCase {
525520
wait(for: [submitExpectation], timeout: 0)
526521
}
527522

528-
func testRegisterChaffBackgroundTask() {
529-
let registerExpectation = self.expectation(description: "A background task with the given identifier is registered")
530-
let bgSchedulerMock = BGTaskSchedulerMock()
531-
bgSchedulerMock.registerHandler = { identifier, launchHanlder in
532-
registerExpectation.fulfill()
533-
return true
534-
}
535-
let exposureManager = ExposureManager(backgroundTaskScheduler: bgSchedulerMock)
536-
exposureManager.registerChaffBackgroundTask()
537-
wait(for: [registerExpectation], timeout: 0)
538-
}
539-
540-
func testSubmitChaffBackgroundTask() {
541-
let mockEnManager = ENManagerMock()
542-
mockEnManager.exposureNotificationStatusHandler = {
543-
return .active
544-
}
545-
let submitExpectation = self.expectation(description: "A background task request is submitted")
546-
let bgSchedulerMock = BGTaskSchedulerMock()
547-
bgSchedulerMock.submitHandler = { taskRequest in
548-
submitExpectation.fulfill()
549-
}
550-
let exposureManager = ExposureManager(exposureNotificationManager: mockEnManager,
551-
backgroundTaskScheduler: bgSchedulerMock)
552-
exposureManager.scheduleChaffBackgroundTaskIfNeeded()
553-
wait(for: [submitExpectation], timeout: 0)
554-
}
555-
556523
func testRegisterDeleteOldExposuresBackgroundTask() {
557524
let registerExpectation = self.expectation(description: "A background task with the given identifier is registered")
558525
let bgSchedulerMock = BGTaskSchedulerMock()

src/AffectedUserFlow/verificationAPI.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,15 @@ interface VerifiedCodeResponse {
4949

5050
export const postCode = async (
5151
code: string,
52-
isChaffRequest = false,
5352
): Promise<NetworkResponse<CodeVerificationSuccess, CodeVerificationError>> => {
5453
const data = {
5554
code,
5655
}
5756

58-
const headers = isChaffRequest
59-
? { ...defaultHeaders, "x-chaff": "1" }
60-
: defaultHeaders
61-
6257
try {
6358
const response = (await fetchWithTimeout(verifyUrl, {
6459
method: "POST",
65-
headers: headers,
60+
headers: defaultHeaders,
6661
body: JSON.stringify(data),
6762
})) as Response
6863

@@ -118,22 +113,18 @@ export type TokenVerificationError =
118113
export const postTokenAndHmac = async (
119114
token: Token,
120115
hmacDigest: string,
121-
isChaffRequest = false,
122116
): Promise<
123117
NetworkResponse<TokenVerificationSuccess, TokenVerificationError>
124118
> => {
125119
const data = {
126120
token,
127121
ekeyhmac: hmacDigest,
128122
}
129-
const headers = isChaffRequest
130-
? { ...defaultHeaders, "x-Chaff": "1" }
131-
: defaultHeaders
132123

133124
try {
134125
const response = await fetch(certificateUrl, {
135126
method: "POST",
136-
headers,
127+
headers: defaultHeaders,
137128
body: JSON.stringify(data),
138129
})
139130

src/ExposureContext.tsx

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { ExposureKey } from "./exposureKey"
1111
import { ExposureInfo } from "./exposure"
1212
import { useProductAnalyticsContext } from "./ProductAnalytics/Context"
1313
import * as NativeModule from "./gaen/nativeModule"
14-
import { calculateHmac } from "./AffectedUserFlow/hmac"
15-
import * as API from "./AffectedUserFlow/verificationAPI"
1614

1715
type Posix = number
1816

@@ -66,27 +64,6 @@ const ExposureProvider: FunctionComponent = ({ children }) => {
6664
})
6765
}, [])
6866

69-
const sendChaffRequest = useCallback(async () => {
70-
const code = Math.random().toString().substring(2, 10)
71-
const response = await API.postCode(code, true)
72-
73-
if (response.kind === "success") {
74-
const token = response.body.token
75-
const exposureKeys = await NativeModule.fetchChaffKeys()
76-
const [hmacDigest] = await calculateHmac(exposureKeys)
77-
78-
const certResponse = await API.postTokenAndHmac(token, hmacDigest, true)
79-
80-
if (certResponse.kind === "success") {
81-
trackEvent("epi_analytics", "chaff_request_sent")
82-
} else {
83-
trackEvent("epi_analytics", "chaff_request_failed")
84-
}
85-
} else {
86-
trackEvent("epi_analytics", "chaff_request_failed")
87-
}
88-
}, [trackEvent])
89-
9067
const refreshExposureInfo = useCallback(async () => {
9168
const exposureInfo = await NativeModule.getCurrentExposures()
9269
setExposureInfo(exposureInfo)
@@ -96,26 +73,18 @@ const ExposureProvider: FunctionComponent = ({ children }) => {
9673
}, [])
9774

9875
useEffect(() => {
99-
// Exposures subscription
100-
const exposuresSubscription = NativeModule.subscribeToExposureEvents(
76+
const subscription = NativeModule.subscribeToExposureEvents(
10177
(exposureInfo: ExposureInfo) => {
10278
setExposureInfo(exposureInfo)
10379
getLastExposureDetectionDate()
10480
},
10581
)
10682
getLastExposureDetectionDate()
10783

108-
// Chaff subscription
109-
const chaffSubscription = NativeModule.subscribeToChaffRequestEvents(() => {
110-
sendChaffRequest()
111-
})
112-
sendChaffRequest()
113-
11484
return () => {
115-
exposuresSubscription.remove()
116-
chaffSubscription.remove()
85+
subscription.remove()
11786
}
118-
}, [getLastExposureDetectionDate, sendChaffRequest])
87+
}, [getLastExposureDetectionDate])
11988

12089
useEffect(() => {
12190
const subscription = NativeModule.subscribeToExposureEvents(() => {

0 commit comments

Comments
 (0)