-
Notifications
You must be signed in to change notification settings - Fork 157
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
Fix telemetry opt-out through attribution dialog #758
Conversation
b2678aa
to
5b5cb77
Compare
df734dc
to
c955538
Compare
This reverts commit 9a0c82b.
c955538
to
3c8665f
Compare
5e31878
to
4ecaa56
Compare
Tests/MapboxMapsTests/Ornaments/InfoButton/MapboxInfoButtonOrnamentTests.swift
Outdated
Show resolved
Hide resolved
4ecaa56
to
a677542
Compare
17324af
to
872b82c
Compare
|
||
final class EventsManagerTests: XCTestCase { | ||
|
||
let eventsManager = EventsManager(accessToken: "empty") |
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.
Would like to see this be created on setUp and destroyed on tearDown. XCTestCase instances don't necessarily get deallocated right away, so keeping this alive throughout the test run could lead to unintended effects for other tests.
override class func setUp() { | ||
UserDefaults.mme_configuration().set(true, forKey: "MMECollectionEnabledInSimulator") | ||
} |
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.
Why is this necessary?
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.
UserDefaults.mme_configuration().mme_isCollectionEnabled
alsways return false
on simulator.
I guess this one can be moved to testMGLMapboxMetricsEqualsMMECollectionEnabled
.
func testUserDefaultsDynamicProperty() { | ||
UserDefaults.standard.MGLMapboxMetricsEnabled = true | ||
XCTAssertEqual(UserDefaults.standard.bool(forKey: "MGLMapboxMetricsEnabled"), true) | ||
|
||
UserDefaults.standard.MGLMapboxMetricsEnabled = false | ||
XCTAssertEqual(UserDefaults.standard.bool(forKey: "MGLMapboxMetricsEnabled"), false) | ||
} |
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.
Can you test the getter too?
CHANGELOG.md
Outdated
@@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. | |||
* Make `PointAnnotation.Image`'s fields public. ([#753](https://github.com/mapbox/mapbox-maps-ios/pull/753)) | |||
* Passing an unsupported locale into `Style.localizeLabels(into:forLayerIds:)` throws an error instead of crashing. ([#752](https://github.com/mapbox/mapbox-maps-ios/pull/752)) | |||
* Set `MapboxMap` flags during gestures and animations. ([#754](https://github.com/mapbox/mapbox-maps-ios/pull/754)) | |||
* Fix telemetry opt-out through attribution dialog (better fix). ([#758](https://github.com/mapbox/mapbox-maps-ios/pull/758)) |
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.
I'm not sure we should compare fixes in the changelog
override class func setUp() { | ||
UserDefaults.mme_configuration().set(true, forKey: "MMECollectionEnabledInSimulator") | ||
} |
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.
UserDefaults.mme_configuration().mme_isCollectionEnabled
alsways return false
on simulator.
I guess this one can be moved to testMGLMapboxMetricsEqualsMMECollectionEnabled
.
internal class EventsManager: EventsListener { | ||
private enum Constants { | ||
static let MGLAPIClientUserAgentBase = "mapbox-maps-ios" | ||
} | ||
|
||
var telemetry: TelemetryProtocol! | ||
private var metricsEnabledObservation: NSKeyValueObservation? |
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.
Please add
deinit {
metricsEnabledObservation?.invalidate()
}
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.
It was there initially, but Andrew mentioned in one of his comments that I should remove it :)
#758 (comment)
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.
Oh, I see, thanks!
init(with telemetry: TelemetryProtocol?) { | ||
self.telemetry = telemetry | ||
metricsEnabledObservation = UserDefaults.standard.observe(\.MGLMapboxMetricsEnabled, options: [.new, .initial]) { _, change in | ||
guard let newValue = change.newValue else { return } |
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.
Should we care about thread safety here? I can't find if this code is called from the same queue the changes are made.
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.
@macdrevx what do you think?
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.
UserDefaults
is thread safe, including mme_configuration().mme_isCollectionEnabled
, but I don't think pauseOrResumeMetricsCollectionIfRequired()
is. Seems like a good idea to async to the main queue in this block.
} | ||
|
||
func testMGLMapboxMetricsEqualsMMECollectionEnabled() { | ||
UserDefaults.standard.MGLMapboxMetricsEnabled = true |
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.
Could you add UserDefaults.mme_configuration().mme_isCollectionEnabled = false
before this call to verify the switching works in both cases?
a3efeda
to
5cfb86d
Compare
|
||
init(accessToken: String) { | ||
let sdkVersion = "10.0.0" |
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.
@macdrevx Not sure, why was it hardcoded before. Is it fine to read it from the bundle?
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.
Reading from the bundle seems good to me.
be5976e
to
f374a71
Compare
f374a71
to
cd2da51
Compare
cd2da51
to
36a903f
Compare
internal class EventsManager: EventsListener { | ||
private enum Constants { | ||
static let MGLAPIClientUserAgentBase = "mapbox-maps-ios" | ||
} | ||
|
||
var telemetry: TelemetryProtocol! | ||
private var metricsEnabledObservation: NSKeyValueObservation? |
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.
Oh, I see, thanks!
self.telemetry = telemetry | ||
metricsEnabledObservation = UserDefaults.standard.observe(\.MGLMapboxMetricsEnabled, options: [.initial, .new]) { _, change in | ||
DispatchQueue.main.async { | ||
guard let newValue = change.newValue else { return } |
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.
NIT: We can move this outside of the async call
Add prerequisites section to debug-env/README.md
PRs must be submitted under the terms of our Contributor License Agreement CLA.
Fixes: < Link to related issues that will be fixed by this pull request, if they exist >
Pull request checklist:
mapbox-maps-ios
changelog:<changelog></changelog>
.Summary of changes
User impact (optional)