ios_util.mm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/ios/ios_util.h"
  5. #import <Foundation/Foundation.h>
  6. #import <UIKit/UIKit.h>
  7. #include <stddef.h>
  8. #include "base/mac/foundation_util.h"
  9. #include "base/system/sys_info.h"
  10. namespace {
  11. // Return a 3 elements array containing the major, minor and bug fix version of
  12. // the OS.
  13. const int32_t* OSVersionAsArray() {
  14. int32_t* digits = new int32_t[3];
  15. base::SysInfo::OperatingSystemVersionNumbers(
  16. &digits[0], &digits[1], &digits[2]);
  17. return digits;
  18. }
  19. std::string* g_icudtl_path_override = nullptr;
  20. } // namespace
  21. namespace base {
  22. namespace ios {
  23. bool IsRunningOnIOS12OrLater() {
  24. static const bool is_running_on_or_later = IsRunningOnOrLater(12, 0, 0);
  25. return is_running_on_or_later;
  26. }
  27. bool IsRunningOnIOS13OrLater() {
  28. static const bool is_running_on_or_later = IsRunningOnOrLater(13, 0, 0);
  29. return is_running_on_or_later;
  30. }
  31. bool IsRunningOnIOS14OrLater() {
  32. static const bool is_running_on_or_later = IsRunningOnOrLater(14, 0, 0);
  33. return is_running_on_or_later;
  34. }
  35. bool IsRunningOnIOS15OrLater() {
  36. static const bool is_running_on_or_later = IsRunningOnOrLater(15, 0, 0);
  37. return is_running_on_or_later;
  38. }
  39. bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
  40. static const int32_t* current_version = OSVersionAsArray();
  41. int32_t version[] = {major, minor, bug_fix};
  42. for (size_t i = 0; i < std::size(version); i++) {
  43. if (current_version[i] != version[i])
  44. return current_version[i] > version[i];
  45. }
  46. return true;
  47. }
  48. bool IsInForcedRTL() {
  49. NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  50. return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
  51. }
  52. void OverridePathOfEmbeddedICU(const char* path) {
  53. DCHECK(!g_icudtl_path_override);
  54. g_icudtl_path_override = new std::string(path);
  55. }
  56. FilePath FilePathOfEmbeddedICU() {
  57. if (g_icudtl_path_override) {
  58. return FilePath(*g_icudtl_path_override);
  59. }
  60. return FilePath();
  61. }
  62. bool IsMultipleScenesSupported() {
  63. if (@available(iOS 13, *)) {
  64. return UIApplication.sharedApplication.supportsMultipleScenes;
  65. }
  66. return false;
  67. }
  68. bool IsApplicationPreWarmed() {
  69. return [NSProcessInfo.processInfo.environment objectForKey:@"ActivePrewarm"];
  70. }
  71. } // namespace ios
  72. } // namespace base