-
-
Notifications
You must be signed in to change notification settings - Fork 372
feat(anr): Disable ANR tracking for widgets, live activities, action, intent and share extensions #6670
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
Open
philprime
wants to merge
23
commits into
main
Choose a base branch
from
philprime/disable-live-activity-widgets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,812
β65
Open
feat(anr): Disable ANR tracking for widgets, live activities, action, intent and share extensions #6670
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d68023b
chore: Disable SDK for widget, intent and live activities
philprime f8693fb
add sample for widgets, widgets control and live activities
philprime c2d4e47
WIP
philprime 9d5030b
WIP
philprime 25707b5
WIP
philprime 0965325
WIP
philprime 0a6a5bc
Merge remote-tracking branch 'origin/main' into philprime/disable-livβ¦
philprime ec84a09
add more tests
philprime 33233fc
Merge remote-tracking branch 'origin/main' into philprime/disable-livβ¦
philprime 41d3c2d
cleanup
philprime 9c83007
cleanup
philprime 6613d3b
removed local changes
philprime 00bb563
removed project files
philprime 1107338
wip
philprime 092c5bc
refactored live activity widget into separate target
philprime c756679
fixes
philprime 403874a
Remove generated project
philprime 11d7087
Merge branch 'main' into philprime/disable-live-activity-widgets
philprime 104048f
Test: Restore SentryExtensionDetector in ANR tests
cursoragent 4606e35
Fix: Update Info.plist path in ActionExtension config
cursoragent dee4d83
Merge remote-tracking branch 'origin/main' into philprime/disable-livβ¦
philprime 3f3b3b9
refactor ANR tests
philprime c289fbf
refactor: Remove @testable from Sentry imports in ActionViewControlleβ¦
philprime 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
| #include "../Shared/Config/_Common.xcconfig" | ||
|
|
||
| PRODUCT_BUNDLE_IDENTIFIER = io.sentry.sample.iOS-Swift.ActionExtension | ||
| INFOPLIST_FILE = iOS-Swift-ActionExtension/Resources/Info.plist | ||
|
|
||
| PROVISIONING_PROFILE_SPECIFIER_Debug = match Development io.sentry.sample.iOS-Swift.ActionExtension | ||
| PROVISIONING_PROFILE_SPECIFIER_Test = match Development io.sentry.sample.iOS-Swift.ActionExtension | ||
| PROVISIONING_PROFILE_SPECIFIER_TestCI = match Development io.sentry.sample.iOS-Swift.ActionExtension | ||
| PROVISIONING_PROFILE_SPECIFIER_Release = match AppStore io.sentry.sample.iOS-Swift.ActionExtension | ||
| PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*] = $(PROVISIONING_PROFILE_SPECIFIER_$(CONFIGURATION)) | ||
| PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*] = | ||
|
|
||
| CODE_SIGN_STYLE = Manual | ||
|
|
||
| SUPPORTED_PLATFORMS = iphoneos iphonesimulator | ||
|
|
||
| SWIFT_OBJC_BRIDGING_HEADER = iOS-Swift/Tools/iOS-Swift-Bridging-Header.h | ||
|
|
||
| // Runtime search paths for app extensions to find frameworks in parent app | ||
| LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @executable_path/../../Frameworks | ||
49 changes: 49 additions & 0 deletions
49
Samples/iOS-Swift/iOS-Swift-ActionExtension/Resources/Info.plist
This file contains hidden or 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,49 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>$(DEVELOPMENT_LANGUAGE)</string> | ||
| <key>CFBundleDisplayName</key> | ||
| <string>$(PRODUCT_NAME)</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>$(EXECUTABLE_NAME)</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>$(PRODUCT_NAME)</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>$(MARKETING_VERSION)</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>$(CURRENT_PROJECT_VERSION)</string> | ||
| <key>GIT_BRANCH</key> | ||
| <string><branch></string> | ||
| <key>GIT_COMMIT_HASH</key> | ||
| <string><sha></string> | ||
| <key>GIT_STATUS_CLEAN</key> | ||
| <string><status></string> | ||
| <key>NSExtension</key> | ||
| <dict> | ||
| <key>NSExtensionPointIdentifier</key> | ||
| <string>com.apple.ui-services</string> | ||
| <key>NSExtensionPrincipalClass</key> | ||
| <string>$(PRODUCT_MODULE_NAME).ActionViewController</string> | ||
| <key>NSExtensionAttributes</key> | ||
| <dict> | ||
| <key>NSExtensionActivationRule</key> | ||
| <dict> | ||
| <key>NSExtensionActivationSupportsText</key> | ||
| <true/> | ||
| <key>NSExtensionActivationSupportsWebURLWithMaxCount</key> | ||
| <integer>1</integer> | ||
| <key>NSExtensionActivationSupportsImageWithMaxCount</key> | ||
| <integer>1</integer> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
106 changes: 106 additions & 0 deletions
106
Samples/iOS-Swift/iOS-Swift-ActionExtension/Sources/ActionViewController.swift
This file contains hidden or 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,106 @@ | ||
| import Sentry | ||
| @_spi(Private) import Sentry | ||
| import SentrySampleShared | ||
| import UIKit | ||
| import UniformTypeIdentifiers | ||
|
|
||
| class ActionViewController: UIViewController { | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| super.init(coder: coder) | ||
| setupSentry() | ||
| } | ||
|
|
||
| override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { | ||
| super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | ||
| setupSentry() | ||
| } | ||
|
|
||
| private func setupSentry() { | ||
| // Prevent double initialization - SentrySDK.start() can be called multiple times | ||
| // but we want to avoid unnecessary re-initialization | ||
| guard !SentrySDK.isEnabled else { | ||
| return | ||
| } | ||
|
|
||
| // For this extension we need a specific configuration set, therefore we do not use the shared sample initializer | ||
| SentrySDK.start { options in | ||
| options.dsn = SentrySDKWrapper.defaultDSN | ||
| options.debug = true | ||
|
|
||
| // App Hang Tracking must be enabled, but should not be installed | ||
| options.enableAppHangTracking = true | ||
| } | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
|
|
||
| setupUI() | ||
| } | ||
|
|
||
| func setupUI() { | ||
| view.backgroundColor = .systemBackground | ||
|
|
||
| setupDoneButton() | ||
| setupStatusChecklist() | ||
| } | ||
|
|
||
| var isANRInstalled: Bool { | ||
| return isSentryEnabled && SentrySDKInternal.trimmedInstalledIntegrationNames().contains("ANRTracking") | ||
| } | ||
|
|
||
| var isSentryEnabled: Bool { | ||
| SentrySDK.isEnabled | ||
| } | ||
|
|
||
| // MARK: - UI | ||
|
|
||
| func setupDoneButton() { | ||
| var configuration = UIButton.Configuration.borderedProminent() | ||
| configuration.title = "Done" | ||
| configuration.baseBackgroundColor = .systemBlue | ||
| configuration.buttonSize = .large | ||
|
|
||
| let button = UIButton(configuration: configuration) | ||
| button.addTarget(self, action: #selector(doneAction(_:)), for: .touchUpInside) | ||
| view.addSubview(button) | ||
|
|
||
| button.translatesAutoresizingMaskIntoConstraints = false | ||
| NSLayoutConstraint.activate([ | ||
| button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), | ||
| button.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16), | ||
| button.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16) | ||
| ]) | ||
| } | ||
|
|
||
| @objc func doneAction(_ sender: UIButton) { | ||
| SentrySDK.capture(message: "iOS-Swift-ActionExtension: done called") | ||
| let returnItems = extensionContext?.inputItems as? [NSExtensionItem] ?? [] | ||
| extensionContext?.completeRequest(returningItems: returnItems, completionHandler: nil) | ||
| } | ||
|
|
||
| func setupStatusChecklist() { | ||
| let stack = UIStackView() | ||
| stack.axis = .vertical | ||
| stack.spacing = 8 | ||
| view.addSubview(stack) | ||
|
|
||
| stack.translatesAutoresizingMaskIntoConstraints = false | ||
| NSLayoutConstraint.activate([ | ||
| stack.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
| stack.centerYAnchor.constraint(equalTo: view.centerYAnchor) | ||
| ]) | ||
|
|
||
| let sdkStatusLabel = UILabel() | ||
| sdkStatusLabel.text = isSentryEnabled ? "β Sentry is enabled" : "β Sentry is not enabled" | ||
| sdkStatusLabel.textAlignment = .center | ||
| stack.addArrangedSubview(sdkStatusLabel) | ||
|
|
||
| let anrStatusLabel = UILabel() | ||
| // We want the ANR integration to be disabled for share extensions due to false-positives | ||
| anrStatusLabel.text = !isANRInstalled ? "β ANR Tracking not installed" : "β ANR Tracking installed" | ||
| anrStatusLabel.textAlignment = .center | ||
| stack.addArrangedSubview(anrStatusLabel) | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| #include "../Shared/Config/_Common.xcconfig" | ||
|
|
||
| PRODUCT_BUNDLE_IDENTIFIER = io.sentry.sample.iOS-Swift.IntentExtension | ||
| INFOPLIST_FILE = iOS-Swift-IntentExtension/Resources/Info.plist | ||
|
|
||
| PROVISIONING_PROFILE_SPECIFIER_Debug = match Development io.sentry.sample.iOS-Swift.IntentExtension | ||
| PROVISIONING_PROFILE_SPECIFIER_Test = match Development io.sentry.sample.iOS-Swift.IntentExtension | ||
| PROVISIONING_PROFILE_SPECIFIER_TestCI = match Development io.sentry.sample.iOS-Swift.IntentExtension | ||
| PROVISIONING_PROFILE_SPECIFIER_Release = match AppStore io.sentry.sample.iOS-Swift.IntentExtension | ||
| PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*] = $(PROVISIONING_PROFILE_SPECIFIER_$(CONFIGURATION)) | ||
| PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*] = | ||
|
|
||
| CODE_SIGN_STYLE = Manual | ||
|
|
||
| SUPPORTED_PLATFORMS = iphoneos iphonesimulator | ||
|
|
||
| SWIFT_OBJC_BRIDGING_HEADER = iOS-Swift/Tools/iOS-Swift-Bridging-Header.h | ||
|
|
||
| // Runtime search paths for app extensions to find frameworks in parent app | ||
| LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @executable_path/../../Frameworks |
48 changes: 48 additions & 0 deletions
48
Samples/iOS-Swift/iOS-Swift-IntentExtension/Resources/Info.plist
This file contains hidden or 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,48 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>$(DEVELOPMENT_LANGUAGE)</string> | ||
| <key>CFBundleDisplayName</key> | ||
| <string>$(PRODUCT_NAME)</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>$(EXECUTABLE_NAME)</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>$(PRODUCT_NAME)</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>$(MARKETING_VERSION)</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>$(CURRENT_PROJECT_VERSION)</string> | ||
| <key>GIT_BRANCH</key> | ||
| <string><branch></string> | ||
| <key>GIT_COMMIT_HASH</key> | ||
| <string><sha></string> | ||
| <key>GIT_STATUS_CLEAN</key> | ||
| <string><status></string> | ||
| <key>NSExtension</key> | ||
| <dict> | ||
| <key>NSExtensionAttributes</key> | ||
| <dict> | ||
| <key>IntentsRestrictedWhileLocked</key> | ||
| <array/> | ||
| <key>IntentsSupported</key> | ||
| <array> | ||
| <string>INSendMessageIntent</string> | ||
| <string>INSearchForMessagesIntent</string> | ||
| <string>INSetMessageAttributeIntent</string> | ||
| </array> | ||
| </dict> | ||
| <key>NSExtensionPointIdentifier</key> | ||
| <string>com.apple.intents-service</string> | ||
| <key>NSExtensionPrincipalClass</key> | ||
| <string>$(PRODUCT_MODULE_NAME).IntentHandler</string> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
78 changes: 78 additions & 0 deletions
78
Samples/iOS-Swift/iOS-Swift-IntentExtension/Sources/IntentHandler.swift
This file contains hidden or 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,78 @@ | ||
| import Intents | ||
| import Sentry | ||
| @_spi(Private) import Sentry | ||
| import SentrySampleShared | ||
|
|
||
| class IntentHandler: INExtension, INSendMessageIntentHandling { | ||
|
|
||
| override init() { | ||
| super.init() | ||
| setupSentry() | ||
| } | ||
|
|
||
| override func handler(for intent: INIntent) -> Any { | ||
| setupSentry() | ||
| return self | ||
| } | ||
|
|
||
| private func setupSentry() { | ||
| // Prevent double initialization - SentrySDK.start() can be called multiple times | ||
| // but we want to avoid unnecessary re-initialization | ||
| guard !SentrySDK.isEnabled else { | ||
| return | ||
| } | ||
|
|
||
| // For this extension we need a specific configuration set, therefore we do not use the shared sample initializer | ||
| SentrySDK.start { options in | ||
| options.dsn = SentrySDKWrapper.defaultDSN | ||
| options.debug = true | ||
|
|
||
| // App Hang Tracking must be enabled, but should not be installed | ||
| options.enableAppHangTracking = true | ||
| } | ||
| } | ||
|
|
||
| // MARK: - INSendMessageIntentHandling | ||
|
|
||
| func resolveRecipients(for intent: INSendMessageIntent, with completion: @escaping ([INSendMessageRecipientResolutionResult]) -> Void) { | ||
| let person = INPerson( | ||
| personHandle: INPersonHandle(value: "john-snow", type: .unknown), | ||
| nameComponents: PersonNameComponents(givenName: "John", familyName: "Snow"), | ||
| displayName: "John Snow", | ||
| image: nil, | ||
| contactIdentifier: nil, | ||
| customIdentifier: nil | ||
| ) | ||
| completion([INSendMessageRecipientResolutionResult.success(with: person)]) | ||
| } | ||
|
|
||
| func resolveContent(for intent: INSendMessageIntent, with completion: @escaping (INStringResolutionResult) -> Void) { | ||
| let message = """ | ||
| Sentry Enabled? \(isSentryEnabled ? "β " : "β") | ||
| ANR Disabled? \(!isANRInstalled ? "β " : "β") | ||
| """ | ||
| completion(INStringResolutionResult.success(with: message)) | ||
| } | ||
|
|
||
| func confirm(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) { | ||
| let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) | ||
| completion(INSendMessageIntentResponse(code: .ready, userActivity: userActivity)) | ||
| } | ||
|
|
||
| func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) { | ||
| SentrySDK.capture(message: "iOS-Swift-IntentExtension: handle intent called") | ||
|
|
||
| let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) | ||
| completion(INSendMessageIntentResponse(code: .success, userActivity: userActivity)) | ||
| } | ||
|
|
||
| // MARK: - Helpers | ||
|
|
||
| var isANRInstalled: Bool { | ||
| return isSentryEnabled && SentrySDKInternal.trimmedInstalledIntegrationNames().contains("ANRTracking") | ||
| } | ||
|
|
||
| var isSentryEnabled: Bool { | ||
| SentrySDK.isEnabled | ||
| } | ||
| } |
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.