FBConfiguration.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBConfiguration.h"
  10. #include <dlfcn.h>
  11. #import <UIKit/UIKit.h>
  12. #include "TargetConditionals.h"
  13. #import "FBXCodeCompatibility.h"
  14. #import "XCAXClient_iOS+FBSnapshotReqParams.h"
  15. #import "XCTestPrivateSymbols.h"
  16. #import "XCTestConfiguration.h"
  17. #import "XCUIApplication+FBUIInterruptions.h"
  18. static NSUInteger const DefaultStartingPort = 8100;
  19. static NSUInteger const DefaultMjpegServerPort = 9100;
  20. static NSUInteger const DefaultPortRange = 100;
  21. static char const *const controllerPrefBundlePath = "/System/Library/PrivateFrameworks/TextInput.framework/TextInput";
  22. static NSString *const controllerClassName = @"TIPreferencesController";
  23. static NSString *const FBKeyboardAutocorrectionKey = @"KeyboardAutocorrection";
  24. static NSString *const FBKeyboardPredictionKey = @"KeyboardPrediction";
  25. static NSString *const axSettingsClassName = @"AXSettings";
  26. static BOOL FBShouldUseTestManagerForVisibilityDetection = NO;
  27. static BOOL FBShouldUseSingletonTestManager = YES;
  28. static NSUInteger FBMjpegScalingFactor = 100;
  29. static BOOL FBMjpegShouldFixOrientation = NO;
  30. static NSUInteger FBMjpegServerScreenshotQuality = 25;
  31. static NSUInteger FBMjpegServerFramerate = 10;
  32. // Session-specific settings
  33. static BOOL FBShouldTerminateApp;
  34. static NSNumber* FBMaxTypingFrequency;
  35. static NSUInteger FBScreenshotQuality;
  36. static NSTimeInterval FBCustomSnapshotTimeout;
  37. static BOOL FBShouldUseFirstMatch;
  38. static BOOL FBShouldBoundElementsByIndex;
  39. static BOOL FBIncludeNonModalElements;
  40. static NSString *FBAcceptAlertButtonSelector;
  41. static NSString *FBDismissAlertButtonSelector;
  42. static NSTimeInterval FBWaitForIdleTimeout;
  43. static NSTimeInterval FBAnimationCoolOffTimeout;
  44. static BOOL FBShouldUseCompactResponses;
  45. static NSString *FBElementResponseAttributes;
  46. #if !TARGET_OS_TV
  47. static UIInterfaceOrientation FBScreenshotOrientation;
  48. #endif
  49. @implementation FBConfiguration
  50. + (NSUInteger)defaultTypingFrequency
  51. {
  52. NSInteger defaultFreq = [[NSUserDefaults standardUserDefaults]
  53. integerForKey:@"com.apple.xctest.iOSMaximumTypingFrequency"];
  54. return defaultFreq > 0 ? defaultFreq : 60;
  55. }
  56. + (void)initialize
  57. {
  58. [FBConfiguration resetSessionSettings];
  59. }
  60. #pragma mark Public
  61. + (void)disableRemoteQueryEvaluation
  62. {
  63. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"XCTDisableRemoteQueryEvaluation"];
  64. }
  65. + (void)disableApplicationUIInterruptionsHandling
  66. {
  67. [XCUIApplication fb_disableUIInterruptionsHandling];
  68. }
  69. + (void)enableXcTestDebugLogs
  70. {
  71. ((XCTestConfiguration *)XCTestConfiguration.activeTestConfiguration).emitOSLogs = YES;
  72. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"XCTEmitOSLogs"];
  73. }
  74. + (void)disableAttributeKeyPathAnalysis
  75. {
  76. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"XCTDisableAttributeKeyPathAnalysis"];
  77. }
  78. + (void)disableScreenshots
  79. {
  80. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"DisableScreenshots"];
  81. }
  82. + (void)enableScreenshots
  83. {
  84. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"DisableScreenshots"];
  85. }
  86. + (void)disableScreenRecordings
  87. {
  88. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"DisableDiagnosticScreenRecordings"];
  89. }
  90. + (void)enableScreenRecordings
  91. {
  92. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"DisableDiagnosticScreenRecordings"];
  93. }
  94. + (NSRange)bindingPortRange
  95. {
  96. // 'WebDriverAgent --port 8080' can be passed via the arguments to the process
  97. if (self.bindingPortRangeFromArguments.location != NSNotFound) {
  98. return self.bindingPortRangeFromArguments;
  99. }
  100. // Existence of USE_PORT in the environment implies the port range is managed by the launching process.
  101. if (NSProcessInfo.processInfo.environment[@"USE_PORT"] &&
  102. [NSProcessInfo.processInfo.environment[@"USE_PORT"] length] > 0) {
  103. return NSMakeRange([NSProcessInfo.processInfo.environment[@"USE_PORT"] integerValue] , 1);
  104. }
  105. return NSMakeRange(DefaultStartingPort, DefaultPortRange);
  106. }
  107. + (NSInteger)mjpegServerPort
  108. {
  109. if (self.mjpegServerPortFromArguments != NSNotFound) {
  110. return self.mjpegServerPortFromArguments;
  111. }
  112. if (NSProcessInfo.processInfo.environment[@"MJPEG_SERVER_PORT"] &&
  113. [NSProcessInfo.processInfo.environment[@"MJPEG_SERVER_PORT"] length] > 0) {
  114. return [NSProcessInfo.processInfo.environment[@"MJPEG_SERVER_PORT"] integerValue];
  115. }
  116. return DefaultMjpegServerPort;
  117. }
  118. + (NSUInteger)mjpegScalingFactor
  119. {
  120. return FBMjpegScalingFactor;
  121. }
  122. + (void)setMjpegScalingFactor:(NSUInteger)scalingFactor {
  123. FBMjpegScalingFactor = scalingFactor;
  124. }
  125. + (BOOL)mjpegShouldFixOrientation
  126. {
  127. return FBMjpegShouldFixOrientation;
  128. }
  129. + (void)setMjpegShouldFixOrientation:(BOOL)enabled {
  130. FBMjpegShouldFixOrientation = enabled;
  131. }
  132. + (BOOL)verboseLoggingEnabled
  133. {
  134. return [NSProcessInfo.processInfo.environment[@"VERBOSE_LOGGING"] boolValue];
  135. }
  136. + (void)setShouldUseTestManagerForVisibilityDetection:(BOOL)value
  137. {
  138. FBShouldUseTestManagerForVisibilityDetection = value;
  139. }
  140. + (BOOL)shouldUseTestManagerForVisibilityDetection
  141. {
  142. return FBShouldUseTestManagerForVisibilityDetection;
  143. }
  144. + (void)setShouldUseCompactResponses:(BOOL)value
  145. {
  146. FBShouldUseCompactResponses = value;
  147. }
  148. + (BOOL)shouldUseCompactResponses
  149. {
  150. return FBShouldUseCompactResponses;
  151. }
  152. + (void)setShouldTerminateApp:(BOOL)value
  153. {
  154. FBShouldTerminateApp = value;
  155. }
  156. + (BOOL)shouldTerminateApp
  157. {
  158. return FBShouldTerminateApp;
  159. }
  160. + (void)setElementResponseAttributes:(NSString *)value
  161. {
  162. FBElementResponseAttributes = value;
  163. }
  164. + (NSString *)elementResponseAttributes
  165. {
  166. return FBElementResponseAttributes;
  167. }
  168. + (void)setMaxTypingFrequency:(NSUInteger)value
  169. {
  170. FBMaxTypingFrequency = @(value);
  171. }
  172. + (NSUInteger)maxTypingFrequency
  173. {
  174. if (nil == FBMaxTypingFrequency) {
  175. return [self defaultTypingFrequency];
  176. }
  177. return FBMaxTypingFrequency.integerValue <= 0
  178. ? [self defaultTypingFrequency]
  179. : FBMaxTypingFrequency.integerValue;
  180. }
  181. + (void)setShouldUseSingletonTestManager:(BOOL)value
  182. {
  183. FBShouldUseSingletonTestManager = value;
  184. }
  185. + (BOOL)shouldUseSingletonTestManager
  186. {
  187. return FBShouldUseSingletonTestManager;
  188. }
  189. + (NSUInteger)mjpegServerFramerate
  190. {
  191. return FBMjpegServerFramerate;
  192. }
  193. + (void)setMjpegServerFramerate:(NSUInteger)framerate
  194. {
  195. FBMjpegServerFramerate = framerate;
  196. }
  197. + (NSUInteger)mjpegServerScreenshotQuality
  198. {
  199. return FBMjpegServerScreenshotQuality;
  200. }
  201. + (void)setMjpegServerScreenshotQuality:(NSUInteger)quality
  202. {
  203. FBMjpegServerScreenshotQuality = quality;
  204. }
  205. + (NSUInteger)screenshotQuality
  206. {
  207. return FBScreenshotQuality;
  208. }
  209. + (void)setScreenshotQuality:(NSUInteger)quality
  210. {
  211. FBScreenshotQuality = quality;
  212. }
  213. + (NSTimeInterval)waitForIdleTimeout
  214. {
  215. return FBWaitForIdleTimeout;
  216. }
  217. + (void)setWaitForIdleTimeout:(NSTimeInterval)timeout
  218. {
  219. FBWaitForIdleTimeout = timeout;
  220. }
  221. + (NSTimeInterval)animationCoolOffTimeout
  222. {
  223. return FBAnimationCoolOffTimeout;
  224. }
  225. + (void)setAnimationCoolOffTimeout:(NSTimeInterval)timeout
  226. {
  227. FBAnimationCoolOffTimeout = timeout;
  228. }
  229. // Works for Simulator and Real devices
  230. + (void)configureDefaultKeyboardPreferences
  231. {
  232. void *handle = dlopen(controllerPrefBundlePath, RTLD_LAZY);
  233. Class controllerClass = NSClassFromString(controllerClassName);
  234. TIPreferencesController *controller = [controllerClass sharedPreferencesController];
  235. // Auto-Correction in Keyboards
  236. // 'setAutocorrectionEnabled' Was in TextInput.framework/TIKeyboardState.h over iOS 10.3
  237. if ([controller respondsToSelector:@selector(setAutocorrectionEnabled:)]) {
  238. // Under iOS 10.2
  239. controller.autocorrectionEnabled = NO;
  240. } else if ([controller respondsToSelector:@selector(setValue:forPreferenceKey:)]) {
  241. // Over iOS 10.3
  242. [controller setValue:@NO forPreferenceKey:FBKeyboardAutocorrectionKey];
  243. }
  244. // Predictive in Keyboards
  245. if ([controller respondsToSelector:@selector(setPredictionEnabled:)]) {
  246. controller.predictionEnabled = NO;
  247. } else if ([controller respondsToSelector:@selector(setValue:forPreferenceKey:)]) {
  248. [controller setValue:@NO forPreferenceKey:FBKeyboardPredictionKey];
  249. }
  250. // To dismiss keyboard tutorial on iOS 11+ (iPad)
  251. if ([controller respondsToSelector:@selector(setValue:forPreferenceKey:)]) {
  252. [controller setValue:@YES forPreferenceKey:@"DidShowGestureKeyboardIntroduction"];
  253. if (isSDKVersionGreaterThanOrEqualTo(@"13.0")) {
  254. [controller setValue:@YES forPreferenceKey:@"DidShowContinuousPathIntroduction"];
  255. }
  256. [controller synchronizePreferences];
  257. }
  258. dlclose(handle);
  259. }
  260. + (void)forceSimulatorSoftwareKeyboardPresence
  261. {
  262. #if TARGET_OS_SIMULATOR
  263. // Force toggle software keyboard on.
  264. // This can avoid 'Keyboard is not present' error which can happen
  265. // when send_keys are called by client
  266. [[UIKeyboardImpl sharedInstance] setAutomaticMinimizationEnabled:NO];
  267. if ([(NSObject *)[UIKeyboardImpl sharedInstance]
  268. respondsToSelector:@selector(setSoftwareKeyboardShownByTouch:)]) {
  269. // Xcode 13 no longer has this method
  270. [[UIKeyboardImpl sharedInstance] setSoftwareKeyboardShownByTouch:YES];
  271. }
  272. #endif
  273. }
  274. + (FBConfigurationKeyboardPreference)keyboardAutocorrection
  275. {
  276. return [self keyboardsPreference:FBKeyboardAutocorrectionKey];
  277. }
  278. + (void)setKeyboardAutocorrection:(BOOL)isEnabled
  279. {
  280. [self configureKeyboardsPreference:isEnabled forPreferenceKey:FBKeyboardAutocorrectionKey];
  281. }
  282. + (FBConfigurationKeyboardPreference)keyboardPrediction
  283. {
  284. return [self keyboardsPreference:FBKeyboardPredictionKey];
  285. }
  286. + (void)setKeyboardPrediction:(BOOL)isEnabled
  287. {
  288. [self configureKeyboardsPreference:isEnabled forPreferenceKey:FBKeyboardPredictionKey];
  289. }
  290. + (void)setCustomSnapshotTimeout:(NSTimeInterval)timeout
  291. {
  292. FBCustomSnapshotTimeout = timeout;
  293. }
  294. + (NSTimeInterval)customSnapshotTimeout
  295. {
  296. return FBCustomSnapshotTimeout;
  297. }
  298. + (void)setSnapshotMaxDepth:(int)maxDepth
  299. {
  300. FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @(maxDepth));
  301. }
  302. + (int)snapshotMaxDepth
  303. {
  304. return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue];
  305. }
  306. + (void)setUseFirstMatch:(BOOL)enabled
  307. {
  308. FBShouldUseFirstMatch = enabled;
  309. }
  310. + (BOOL)useFirstMatch
  311. {
  312. return FBShouldUseFirstMatch;
  313. }
  314. + (void)setBoundElementsByIndex:(BOOL)enabled
  315. {
  316. FBShouldBoundElementsByIndex = enabled;
  317. }
  318. + (BOOL)boundElementsByIndex
  319. {
  320. return FBShouldBoundElementsByIndex;
  321. }
  322. + (void)setIncludeNonModalElements:(BOOL)isEnabled
  323. {
  324. FBIncludeNonModalElements = isEnabled;
  325. }
  326. + (BOOL)includeNonModalElements
  327. {
  328. return FBIncludeNonModalElements;
  329. }
  330. + (void)setAcceptAlertButtonSelector:(NSString *)classChainSelector
  331. {
  332. FBAcceptAlertButtonSelector = classChainSelector;
  333. }
  334. + (NSString *)acceptAlertButtonSelector
  335. {
  336. return FBAcceptAlertButtonSelector;
  337. }
  338. + (void)setDismissAlertButtonSelector:(NSString *)classChainSelector
  339. {
  340. FBDismissAlertButtonSelector = classChainSelector;
  341. }
  342. + (NSString *)dismissAlertButtonSelector
  343. {
  344. return FBDismissAlertButtonSelector;
  345. }
  346. #if !TARGET_OS_TV
  347. + (BOOL)setScreenshotOrientation:(NSString *)orientation error:(NSError **)error
  348. {
  349. // Only UIInterfaceOrientationUnknown is over iOS 8. Others are over iOS 2.
  350. // https://developer.apple.com/documentation/uikit/uiinterfaceorientation/uiinterfaceorientationunknown
  351. if ([orientation.lowercaseString isEqualToString:@"portrait"]) {
  352. FBScreenshotOrientation = UIInterfaceOrientationPortrait;
  353. } else if ([orientation.lowercaseString isEqualToString:@"portraitupsidedown"]) {
  354. FBScreenshotOrientation = UIInterfaceOrientationPortraitUpsideDown;
  355. } else if ([orientation.lowercaseString isEqualToString:@"landscaperight"]) {
  356. FBScreenshotOrientation = UIInterfaceOrientationLandscapeRight;
  357. } else if ([orientation.lowercaseString isEqualToString:@"landscapeleft"]) {
  358. FBScreenshotOrientation = UIInterfaceOrientationLandscapeLeft;
  359. } else if ([orientation.lowercaseString isEqualToString:@"auto"]) {
  360. FBScreenshotOrientation = UIInterfaceOrientationUnknown;
  361. } else {
  362. return [[FBErrorBuilder.builder withDescriptionFormat:
  363. @"The orientation value '%@' is not known. Only the following orientation values are supported: " \
  364. "'auto', 'portrait', 'portraitUpsideDown', 'landscapeRight' and 'landscapeLeft'", orientation]
  365. buildError:error];
  366. }
  367. return YES;
  368. }
  369. + (NSInteger)screenshotOrientation
  370. {
  371. return FBScreenshotOrientation;
  372. }
  373. + (NSString *)humanReadableScreenshotOrientation
  374. {
  375. switch (FBScreenshotOrientation) {
  376. case UIInterfaceOrientationPortrait:
  377. return @"portrait";
  378. case UIInterfaceOrientationPortraitUpsideDown:
  379. return @"portraitUpsideDown";
  380. case UIInterfaceOrientationLandscapeRight:
  381. return @"landscapeRight";
  382. case UIInterfaceOrientationLandscapeLeft:
  383. return @"landscapeLeft";
  384. case UIInterfaceOrientationUnknown:
  385. return @"auto";
  386. }
  387. }
  388. #endif
  389. + (void)resetSessionSettings
  390. {
  391. FBShouldTerminateApp = YES;
  392. FBShouldUseCompactResponses = YES;
  393. FBElementResponseAttributes = @"type,label";
  394. FBMaxTypingFrequency = @([self defaultTypingFrequency]);
  395. FBScreenshotQuality = 3;
  396. FBCustomSnapshotTimeout = 15.;
  397. FBShouldUseFirstMatch = NO;
  398. FBShouldBoundElementsByIndex = NO;
  399. // This is diabled by default because enabling it prevents the accessbility snapshot to be taken
  400. // (it always errors with kxIllegalArgument error)
  401. FBIncludeNonModalElements = NO;
  402. FBAcceptAlertButtonSelector = @"";
  403. FBDismissAlertButtonSelector = @"";
  404. FBWaitForIdleTimeout = 10.;
  405. FBAnimationCoolOffTimeout = 2.;
  406. // 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100.
  407. FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50);
  408. #if !TARGET_OS_TV
  409. FBScreenshotOrientation = UIInterfaceOrientationUnknown;
  410. #endif
  411. }
  412. #pragma mark Private
  413. + (FBConfigurationKeyboardPreference)keyboardsPreference:(nonnull NSString *)key
  414. {
  415. Class controllerClass = NSClassFromString(controllerClassName);
  416. TIPreferencesController *controller = [controllerClass sharedPreferencesController];
  417. if ([key isEqualToString:FBKeyboardAutocorrectionKey]) {
  418. if ([controller respondsToSelector:@selector(boolForPreferenceKey:)]) {
  419. return [controller boolForPreferenceKey:FBKeyboardAutocorrectionKey]
  420. ? FBConfigurationKeyboardPreferenceEnabled
  421. : FBConfigurationKeyboardPreferenceDisabled;
  422. } else {
  423. [FBLogger log:@"Updating keyboard autocorrection preference is not supported"];
  424. return FBConfigurationKeyboardPreferenceNotSupported;
  425. }
  426. } else if ([key isEqualToString:FBKeyboardPredictionKey]) {
  427. if ([controller respondsToSelector:@selector(boolForPreferenceKey:)]) {
  428. return [controller boolForPreferenceKey:FBKeyboardPredictionKey]
  429. ? FBConfigurationKeyboardPreferenceEnabled
  430. : FBConfigurationKeyboardPreferenceDisabled;
  431. } else {
  432. [FBLogger log:@"Updating keyboard prediction preference is not supported"];
  433. return FBConfigurationKeyboardPreferenceNotSupported;
  434. }
  435. }
  436. @throw [[FBErrorBuilder.builder withDescriptionFormat:@"No available keyboardsPreferenceKey: '%@'", key] build];
  437. }
  438. + (void)configureKeyboardsPreference:(BOOL)enable forPreferenceKey:(nonnull NSString *)key
  439. {
  440. void *handle = dlopen(controllerPrefBundlePath, RTLD_LAZY);
  441. Class controllerClass = NSClassFromString(controllerClassName);
  442. TIPreferencesController *controller = [controllerClass sharedPreferencesController];
  443. if ([key isEqualToString:FBKeyboardAutocorrectionKey]) {
  444. // Auto-Correction in Keyboards
  445. if ([controller respondsToSelector:@selector(setAutocorrectionEnabled:)]) {
  446. controller.autocorrectionEnabled = enable;
  447. } else {
  448. [controller setValue:@(enable) forPreferenceKey:FBKeyboardAutocorrectionKey];
  449. }
  450. } else if ([key isEqualToString:FBKeyboardPredictionKey]) {
  451. // Predictive in Keyboards
  452. if ([controller respondsToSelector:@selector(setPredictionEnabled:)]) {
  453. controller.predictionEnabled = enable;
  454. } else {
  455. [controller setValue:@(enable) forPreferenceKey:FBKeyboardPredictionKey];
  456. }
  457. }
  458. [controller synchronizePreferences];
  459. dlclose(handle);
  460. }
  461. + (NSString*)valueFromArguments: (NSArray<NSString *> *)arguments forKey: (NSString*)key
  462. {
  463. NSUInteger index = [arguments indexOfObject:key];
  464. if (index == NSNotFound || index == arguments.count - 1) {
  465. return nil;
  466. }
  467. return arguments[index + 1];
  468. }
  469. + (NSUInteger)mjpegServerPortFromArguments
  470. {
  471. NSString *portNumberString = [self valueFromArguments: NSProcessInfo.processInfo.arguments
  472. forKey: @"--mjpeg-server-port"];
  473. NSUInteger port = (NSUInteger)[portNumberString integerValue];
  474. if (port == 0) {
  475. return NSNotFound;
  476. }
  477. return port;
  478. }
  479. + (NSRange)bindingPortRangeFromArguments
  480. {
  481. NSString *portNumberString = [self valueFromArguments:NSProcessInfo.processInfo.arguments
  482. forKey: @"--port"];
  483. NSUInteger port = (NSUInteger)[portNumberString integerValue];
  484. if (port == 0) {
  485. return NSMakeRange(NSNotFound, 0);
  486. }
  487. return NSMakeRange(port, 1);
  488. }
  489. + (void)setReduceMotionEnabled:(BOOL)isEnabled
  490. {
  491. Class settingsClass = NSClassFromString(axSettingsClassName);
  492. AXSettings *settings = [settingsClass sharedInstance];
  493. // Below does not work on real devices because of iOS security model
  494. // (lldb) po settings.reduceMotionEnabled = isEnabled
  495. // 2019-08-21 22:58:19.776165+0900 WebDriverAgentRunner-Runner[322:13361] [User Defaults] Couldn't write value for key ReduceMotionEnabled in CFPrefsPlistSource<0x28111a700> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
  496. if ([settings respondsToSelector:@selector(setReduceMotionEnabled:)]) {
  497. [settings setReduceMotionEnabled:isEnabled];
  498. }
  499. }
  500. + (BOOL)reduceMotionEnabled
  501. {
  502. Class settingsClass = NSClassFromString(axSettingsClassName);
  503. AXSettings *settings = [settingsClass sharedInstance];
  504. if ([settings respondsToSelector:@selector(reduceMotionEnabled)]) {
  505. return settings.reduceMotionEnabled;
  506. }
  507. return NO;
  508. }
  509. @end