• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2012 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifdef UNSAFE_BUFFERS_BUILD
6// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
7#pragma allow_unsafe_buffers
8#endif
9
10#include "base/ios/ios_util.h"
11
12#import <Foundation/Foundation.h>
13#import <UIKit/UIKit.h>
14#include <stddef.h>
15
16#include "base/apple/foundation_util.h"
17#include "base/system/sys_info.h"
18
19namespace {
20
21std::string* g_icudtl_path_override = nullptr;
22
23}  // namespace
24
25namespace base::ios {
26
27bool IsRunningOnIOS16OrLater() {
28  static const bool is_running_on_or_later = IsRunningOnOrLater(16, 0, 0);
29  return is_running_on_or_later;
30}
31
32bool IsRunningOnIOS17OrLater() {
33  static const bool is_running_on_or_later = IsRunningOnOrLater(17, 0, 0);
34  return is_running_on_or_later;
35}
36
37bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
38  static const class OSVersion {
39   public:
40    OSVersion() {
41      SysInfo::OperatingSystemVersionNumbers(
42          &current_version_[0], &current_version_[1], &current_version_[2]);
43    }
44
45    bool IsRunningOnOrLater(int32_t version[3]) const {
46      for (size_t i = 0; i < std::size(current_version_); ++i) {
47        if (current_version_[i] != version[i])
48          return current_version_[i] > version[i];
49      }
50      return true;
51    }
52
53   private:
54    int32_t current_version_[3];
55  } kOSVersion;
56
57  int32_t version[3] = {major, minor, bug_fix};
58  return kOSVersion.IsRunningOnOrLater(version);
59}
60
61bool IsInForcedRTL() {
62  NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
63  return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
64}
65
66void OverridePathOfEmbeddedICU(const char* path) {
67  DCHECK(!g_icudtl_path_override);
68  g_icudtl_path_override = new std::string(path);
69}
70
71FilePath FilePathOfEmbeddedICU() {
72  if (g_icudtl_path_override) {
73    return FilePath(*g_icudtl_path_override);
74  }
75  return FilePath();
76}
77
78#if !BUILDFLAG(IS_IOS_APP_EXTENSION)
79bool IsMultipleScenesSupported() {
80  if (@available(iOS 13, *)) {
81    return UIApplication.sharedApplication.supportsMultipleScenes;
82  }
83  return false;
84}
85#endif
86
87bool IsApplicationPreWarmed() {
88  return [NSProcessInfo.processInfo.environment objectForKey:@"ActivePrewarm"];
89}
90
91}  // namespace base::ios
92