Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Enable voice over mode on device while running in accessibility explo…
Browse files Browse the repository at this point in the history
…ration mode

Summary:
All the FoA have different logic depending on whether device is running in  VoiceOver mode or not. This results in incorrect accessibility being reported through the Flipper plugin.

For example on Instagram we fetch the image descriptions, in Facebook app we group individual elements into the accessibility groups to simplify traversing the screen

This tells device that it is in a voice over mode while inspecting accessibility mode is on meaning that it will be the closest approximation to the

Reviewed By: nscoding

Differential Revision: D49579241

fbshipit-source-id: f3be9057007ee6eefbe3b448f0f97c1fcd2c8f46
  • Loading branch information
Sash Zats authored and facebook-github-bot committed Sep 24, 2023
1 parent 7d77be1 commit f2e402e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ - (void)processNode:(id)node withContext:(UIDContext*)context {
[self processNode:node withSnapshot:false withContext:context];
}

- (void)setTraversalMode:(UIDTraversalMode)traversalMode {
if (_traversalMode == traversalMode) {
return;
}
_traversalMode = traversalMode;
[UIDAllyTraversal setVoiceOverServiceEnabled:traversalMode ==
UIDTraversalModeAccessibilityHierarchy];
}

- (void)processNode:(id)node
withSnapshot:(BOOL)snapshot
withContext:(UIDContext*)context {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface UIDAllyTraversal : NSObject

+ (void)setVoiceOverServiceEnabled:(BOOL)enabled;

@property(nonatomic, class, readonly, getter=isSupported) BOOL supported;

- (instancetype)initWithDescriptorRegister:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#if FB_SONARKIT_ENABLED

#import "UIDAllyTraversal.h"
#import <dlfcn.h>
#import "UIDDescriptorRegister.h"
#import "UIDMetadataRegister.h"
#import "UIDNode.h"
Expand All @@ -34,6 +35,12 @@ + (BOOL)isSupported {
(_accessibilityLeafDescendantsWithOptions:)];
}

+ (void)setVoiceOverServiceEnabled:(BOOL)enabled {
if (self.isSupported) {
_setVoiceOver(enabled);
}
}

- (instancetype)initWithDescriptorRegister:
(UIDDescriptorRegister*)descriptorRegister {
self = [super init];
Expand Down Expand Up @@ -114,6 +121,25 @@ static BOOL _loadAccessibilityFramework(void) {
return isAccessibilityFrameworkLoaded;
}

static void _setVoiceOver(BOOL enabled) {
NSString* const accessibilityUtilitiesPath =
[[NSBundle bundleForClass:UIApplication.class]
.bundleURL.URLByDeletingLastPathComponent
.URLByDeletingLastPathComponent
URLByAppendingPathComponent:
@"PrivateFrameworks/AccessibilityUtilities.framework/AccessibilityUtilities"]
.relativePath;
void* handler = dlopen(
[accessibilityUtilitiesPath cStringUsingEncoding:NSUTF8StringEncoding],
RTLD_NOW);
if (!handler) {
return;
}
void (*_AXSVoiceOverTouchSetEnabled)(BOOL) =
dlsym(handler, "_AXSVoiceOverTouchSetEnabled");
_AXSVoiceOverTouchSetEnabled(enabled);
}

static NSString* _nameForNode(NSObject* node) {
NSMutableArray* const parts = [NSMutableArray new];
if (node.accessibilityLabel.length > 0) {
Expand Down

0 comments on commit f2e402e

Please sign in to comment.